passing data from an activity to an listactivity or listview
Posted
by
wicked14
on Stack Overflow
See other posts from Stack Overflow
or by wicked14
Published on 2012-11-24T23:00:47Z
Indexed on
2012/11/24
23:03 UTC
Read the original article
Hit count: 191
need help on passing data from an activity to an listactivity or listview for an android app. im having problems on passing data to a listview.
what the app do is from addact class the user can input things to do and in the viewact class this will display the activies add by the user in 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();
}
}
});
}
}
© Stack Overflow or respective owner