Reputation: 5826
I need some help creating a listview inside a layout i have. im having torubles creating it properly.
Here is what i got so far.
item.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<LinearLayout
android:id="@+id/listview"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@drawable/list_selector" >
<ImageView
android:id="@+id/imageView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@drawable/gradient_bg"
android:src="@drawable/gs3ultimate" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >
<TextView
android:id="@+id/label"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/thelistarray"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textColor="#555555" />
<TextView
android:id="@+id/summary"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/thelistarry_details"
android:textColor="#555555"
android:textSize="10dp" />
</LinearLayout>
</LinearLayout>
</LinearLayout>
Now its just a image on the left, then 2 textview, Now i believe im gonna need 2 string arrys, one for the titles and the 2nd for the details. and i think a 3rd one for the images. Is that right?
Here some java for my list view
AndroidListViewActivity.java
import android.app.ListActivity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import android.widget.TextView;
public class AndroidListViewActivity extends ListActivity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// storing string resources into Array
String[] list_array = getResources().getStringArray(R.array.list_array);
// Binding resources Array to ListAdapter
this.setListAdapter(new ArrayAdapter<String>(this, R.layout.item, R.id.label, list_array));
ListView lv = getListView();
// listening to single list item on click
lv.setOnItemClickListener(new OnItemClickListener() {
public void onItemClick(AdapterView<?> parent, View view,
int position, long id) {
}
});
}
}
I know that my java is missing adding the details list_array_details. and i dont know how to add it so it populates. Im not yet using the onitemclick yet for my intent's. However would i determine which one is click and what activity to launch? example. i click list item b and want to like activity "b" but when i click a it launches activity "a"
Any help would be greately appreciated, Thanks in advance.
Upvotes: 0
Views: 164