I am new to android application.So my question may seems small to you guys. But for me it is really serious and big.
I have a list of items and on item selection it is showing another list of items. It goes till 4 level in same fashion.
With following code implementation I am able to achieve this but whenever back key is pressed instead of coming to previous listview it is killing my application.
Using java Syntax Highlighting
- <span style="font-weight: bold">MGUI.jav</span>a
Parsed in 0.030 seconds, using GeSHi 1.0.8.4
public class MGUI extends ListActivity {
@Override
public void onCreate(Bundle icicle) {
super.onCreate(icicle);
String[] mStrings = new String[]{"A", "B","C"};
this.setListAdapter(new ArrayAdapter<String>(this,R.layout.mylist, mStrings));
}
protected void onListItemClick(ListView listView, View view, int position, long id)
{
super.onListItemClick(listView, view, position, id);
String[] mStrings = new String[]{"A1", "A2","A3"};
this.setListAdapter(new ArrayAdapter<String>(this,R.layout.mylist, mStrings));
}
}
Using xml Syntax Highlighting
- My mylist.XML
Parsed in 0.000 seconds, using GeSHi 1.0.8.4
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@android:id/text1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceLarge"
android:gravity="center_vertical"
android:paddingLeft="6dip"
android:minHeight="?android:attr/listPreferredItemHeight"
/>
This behaviour seems ok with button event as I am drawing all list on same view.
So,thinking in this way I have changed my code .
Now I have taken two classes.
Using java Syntax Highlighting
- MyList.java
Parsed in 0.029 seconds, using GeSHi 1.0.8.4
public class MyList extends ListActivity {
protected static final int SUB_ACTIVTY_REQUEST_CODE = 99;
private String[] mStrings ={"A", "B", "C"};
public void onCreate(Bundle icicle) {
super.onCreate(icicle);
setContentView(R.layout.list1);
this.setListAdapter(new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, mStrings ));
}
@Override
protected void onListItemClick(ListView l, View v, int position, long id) {
selectedItem = position;
Intent intent = new Intent(MyList.this, List2.class);
super.startActivityForResult(intent, SUB_ACTIVTY_REQUEST_CODE);
}
@Override
protected void onActivityResult(int requestCode, int resultCode,Intent Data) {
super.onActivityResult(requestCode, resultCode, Data);
}
}
Using java Syntax Highlighting
- List2.java
Parsed in 0.032 seconds, using GeSHi 1.0.8.4
public class List2 extends Activity {
private String[] mStrings ={"A1", "A2", "A3"};
@Override
protected void onCreate(Bundle icicle) {
super.onCreate(icicle);
this.setContentView(R.layout.mlist);
this.setListAdapter(new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, mStrings ));
}
}
Using xml Syntax Highlighting
- list1.xml
Parsed in 0.000 seconds, using GeSHi 1.0.8.4
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:textSize="30dip"
android:text="@string/list_title"/>
<ListView
android:id="@id/android:list"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="1"
android:drawSelectorOnTop="false"/>
</LinearLayout>
Using xml Syntax Highlighting
- mlist.xml
Parsed in 0.000 seconds, using GeSHi 1.0.8.4
<?xml version="1.0" encoding="utf-8" ?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical" android:layout_width="fill_parent" android:layout_height="fill_parent" />
In this case I am able to load 1st view,but once a item is being selected, application get crashed.
I can understand I am missing some basics.Please help me.
Thanks,
mani


