Can i define a text view and a list view inside a linear layout.
If yes, then i am trying to define a list view and wants every list item to open a new activity. But my activity doesnt run and it shows “Unfortunately your app is forced to closed”. Please Please help!
Here is the code:
public class Second_listview extends ListActivity
{
static final String[] type = new String[]{
"Array", "Strings"
};
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.second_listview);
// setting up list view
setListAdapter (new ArrayAdapter<String>(this, R.layout.second_listview, type));
ListView list = getListView();
list.setTextFilterEnabled(true);
list.setOnItemClickListener(new OnItemClickListener(){
@Override
public void onItemClick(AdapterView<?> arg0, View view, int arg2,
long arg3) {
// TODO Auto-generated method stub
//liking each list item to start a new activity
switch(arg2)
{
case 1 : Intent myIntent1 = new Intent(view.getContext(), Array_list.class);
startActivityForResult(myIntent1, 0);
break;
case 2 : Intent myIntent2 = new Intent(view.getContext(), String_list.class);
startActivityForResult(myIntent2, 0);
break;
}
}
});
}
}
Set the Id of you listview as “@android:id/list” as mentioned below.
This may be an issue. if possible let us know your layout file also.