1
需要將活動數據傳遞給android應用程序的listactivity或listview。即時通訊數據傳遞給列表視圖時遇到問題。將數據從活動傳遞到列表活動或列表視圖
什麼程序做的是從addact類,用戶可以輸入要做的事情 並在viewact類,這將顯示活動比較ListView中
public class addact extends Activity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.newact);
Button btn1 = (Button)findViewById(R.id.btnsave);
final EditText et1 = (EditText)findViewById(R.id.etactivity);
btn1.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View arg0) {
Intent it = new Intent(addact.this, viewact.class);
it.putExtra("thekey", et1.getText().toString());
startActivity(it);
}
});
}
}
public class viewact extends ListActivity {
String addToDo =getIntent().getExtras().getString("thekey");
String[] toDoAct = new String[] {addToDo };
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.viewact);
setListAdapter(new ArrayAdapter<String>(this, R.layout.viewact,toDoAct));
ListView listView = getListView();
listView.setTextFilterEnabled(true);
listView.setOnItemClickListener(new OnItemClickListener() {
public void onItemClick(AdapterView<?> parent, View view,
int position, long id) {
for (int i=0; i < 2; i++)
{
Toast.makeText(getApplicationContext(),
((TextView) view).getText(), Toast.LENGTH_LONG).show();
}
}
});
}
}