I have a class that extends Activity and inflates another xml layout in the main layout.
Example:
public class PrivateHistory extends Activity{
public void onCreate(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
//Remove title bar
this.requestWindowFeature(Window.FEATURE_NO_TITLE);
//Remove notification bar
this.getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
setContentView(R.layout.main_layout);
viewBundleMessage();
LinearLayout item = (LinearLayout)findViewById(R.id.menu_linear_layout);
View child = getLayoutInflater().inflate(R.layout.menu_list, null);
item.addView(child);
getHistoryInfo();
}
}
Example (menu_list layout):
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical">
<ListView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:id="@+id/listViewMenu">
</ListView>
And there is a getHistoryInfo method that I'm using to retrieve some history information from the db so I can put every record in a ListItem.
Example:
public void getHistoryInfo(){
//removed historyItem + database information
ListView lv = (ListView) findViewById(R.id.listViewMenu);
lv.setAdapter(new ArrayAdapter<String>(this,R.layout.history_list_view, historyItem));
lv.setOnItemClickListener(new OnItemClickListener() {
public void onItemClick(AdapterView<?> parent, View view,
int position, long id) {
showToast(historyItem.get(position).toString());
}
});
}
Example (history_list_view):
<?xml version="1.0" encoding="utf-8"?>
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/noteText"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:textColor="#000000"
android:textSize="14dp"
android:paddingLeft="10dp"
android:paddingRight="10dp"
android:paddingTop="5dp"
android:paddingBottom="5dp"
android:background="@drawable/bg_white_grey"
android:gravity="center_vertical"
android:typeface="serif"
android:layout_marginBottom="10dp"/>
So everything here works, but only if you want to add text into every ListItem. I would like to add images to every ListItems, but how? If this class had extended a ListActivity it wouldn't be that hard, but it extends an Activity. So can anyone help me here?
For anyone that would like to use my app, please go to: http://www.4shared.com/android/tWfbNqZ6/Free_Wallet.html