2012-09-28 74 views
0

我需要一些帮助在布局中创建一个列表视图。即时通讯有可燃物正确创建。ListView内部布局

这是我到目前为止。

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> 

现在,它只是在左侧图像,然后2 TextView的,现在我相信我也会需要2个arrys,一个为标题和细节第二。我认为第三个图像。是对的吗?

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) { 


     } 
     }); 
     } 
    } 

我知道,我的Java缺少添加细节list_array_details。我不知道如何添加它,因此它填充。我还没有使用onitemclick但我的意图。但是,我会确定哪一个是点击以及要启动什么活动?例。我点击列表项目b,并希望喜欢活动“B”,但当我点击它启动活动“A”

任何帮助将greely表示感谢,提前致谢。

+1

使劲一看就明白你要我们帮你什么。看起来有太多你没有得到的东西。我建议你在实际编写代码之前先阅读一些内容。 – Egor

+0

这一切都在这个网站:http://www.vogella.com/articles/AndroidListView/article.html#listview –

+0

尽量有点清楚,以便其中一个或另一个会帮助你。 –

回答

1

您需要有一个用于此目的的自定义适配器才能填充除textview或多个textview之外的其他视图。

就以customadapter herehere