編輯:關於Android編程
一、基本知識點
其實要完成這個功能很簡單:
1、MainActivity
startActivityForResult(intent, 100);//第二個是請求碼
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if(data != null){
if(resultCode == 200){//可以根據請求嗎來判斷,也可以根據結果碼來判斷
String username = data.getStringExtra("username");
et_username.setText(username);
}
}
}
2、MainActivity2
setResult(200,intent);//第一個參數是返回碼
二、代碼
1、MainActivity
package com.example.setresult; import android.os.Bundle; import android.app.Activity; import android.content.Intent; import android.view.Menu; import android.view.View; import android.widget.EditText; public class MainActivity extends Activity { public EditText et_username; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); et_username = (EditText) findViewById(R.id.et_name); } public void get(View view){ Intent intent = new Intent(this, MainActivity2.class); startActivityForResult(intent, 100);//第二個是請求碼 } @Override protected void onActivityResult(int requestCode, int resultCode, Intent data) { super.onActivityResult(requestCode, resultCode, data); if(data != null){ if(resultCode == 200){//可以根據請求嗎來判斷,也可以根據結果碼來判斷 String username = data.getStringExtra("username"); et_username.setText(username); } } } @Override public boolean onCreateOptionsMenu(Menu menu) { // Inflate the menu; this adds items to the action bar if it is present. getMenuInflater().inflate(R.menu.main, menu); return true; } }
2、MainActivity2
package com.example.setresult; import android.app.Activity; import android.content.Intent; import android.graphics.Color; import android.os.Bundle; import android.view.TextureView; import android.view.View; import android.view.ViewGroup; import android.widget.AdapterView; import android.widget.AdapterView.OnItemClickListener; import android.widget.BaseAdapter; import android.widget.ListView; import android.widget.TextView; public class MainActivity2 extends Activity { public ListView listView; public MyAdapter adapter; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main2); listView = (ListView) findViewById(R.id.listview); adapter = new MyAdapter(); listView.setAdapter(adapter); listView.setOnItemClickListener(new MyOnItemClickListener()); } public class MyOnItemClickListener implements OnItemClickListener{ @Override public void onItemClick(AdapterView> arg0, View arg1, int position, long arg3) { Intent intent = new Intent(getApplicationContext(), MainActivity.class); String username = (String) adapter.getItem(position); intent.putExtra("username", username); setResult(200,intent);//第一個參數是返回碼 finish();//講當前的activity結束掉 } } public class MyAdapter extends BaseAdapter{ String names[] = new String[]{ "hjd", "hjd1", "hjd2", "hjd3", "hjd4" }; @Override public int getCount() { return names.length; } @Override public Object getItem(int position) { return names[position]; } @Override public long getItemId(int position) { return position; } @Override public View getView(int position, View arg1, ViewGroup arg2) { TextView tv = new TextView(getApplicationContext()); tv.setText(names[position]); tv.setTextSize(25); tv.setTextColor(Color.GREEN); return tv; } } }
三、源碼下載
http://download.csdn.net/detail/caihongshijie6/7793215
四、效果圖
本文介紹calabash-android的命令行的使用,通過例子,熟悉calabash-android所調用的ruby api和常用控制台命令, 如query, touc
今年3月,Google 破天荒提前半年發布了 Android N 開發者預覽版。當然,作為一個不合格的谷粉並沒有第一時間體驗安裝,因為至今仍然能夠回憶起來去年今日此門中(
AChartEngine是一個很強大的圖表引擎,我在上學的時候就接觸過,並且利用它做了一個傳感器的應用,想想現在也很久遠了,今天就把這個app的源碼貼出來供其他人研究這款
前言Universal-Image-Loader,android-Volley,Picasso、Fresco和Glide五大Android開源組件加載網絡圖片比較。在An