I am sorry in advance. I know this must be straight forward. Quite a novice with android. I am creating a main activity and trying to call another activity with the help of intent. Other activity contains a list view. I am trying to show simple strings in the list view. So I think that I don't need to write any of get view. Just AdapterView should work fine. Some code to explain more what I am upto is as follows : Main Activity button onClick method is as follows :
public void manage(View view) {
Intent managerIntent;
managerIntent = new Intent( this,ShowActivity.class);
managerIntent.putExtra(FILE_URI, mediaStorageDir.getAbsolutePath());
startActivity(managerIntent);
}
ShowActivity is as follows:
public class ShowActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
ArrayList<String> strings = new ArrayList<String>();
Intent intent = getIntent();
MyService sc = new MyService()
sc.fill(strings,intent);
final ArrayAdapter<String> ListObject = new ArrayAdapter<String>(ShowReceiptsActivity.this,
android.R.layout.simple_list_item_1, strings);
ListView listView = (ListView)findViewById(R.id.listView);// This line gives null pointer exception
listView.setAdapter(ListObject);
setContentView(R.layout.activity_show_receipts);
}
}
activity_show.xml is as follows:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context="com.receiptboss.manager.ShowReceiptsActivity">
<ListView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/listView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context="com.receiptboss.manager.ShowReceiptsActivity"/>
</LinearLayout>
Any help is greatly appreciated.