2011-09-07 90 views
1

我顯示一個列表視圖有兩個textview。第一個textview用於顯示位置的名稱和第二個用於顯示地址。我anm從數據庫中檢索值並在arraylist中添加這些值。我用一個名爲myadapter的自定義arrayadapter類在那裏膨脹了兩個textview,但是當我設置其中一個textview的textviewresourse id時,我在單個textview中獲取了這兩個值。我希望他們在sepetate textviews。這是我在這我在一個ArrayListlistview中有兩個textview與arrayadapter和arraylist

c.move(3); 
      // x1=c.getColumnIndex("_id"); 
      // y1=c.getColumnIndex("latitude"); 
      // z1=c.getColumnIndex("longiitude"); 
      // w1=c.getColumnIndex("address"); 
       x = c.getColumnName(0); 
       y = c.getColumnName(1); 
       z = c.getColumnName(2); 
       w = c.getColumnName(3); 
       n=c.getColumnName(4); 

    // tv_id.setText(x.toString().toUpperCase()); 
      //tv_lat.setText(y.toString().toUpperCase()); 
      //tv_lon.setText(z.toString().toUpperCase()); 
      // tv_add.setText(w.toString().toUpperCase()); 
      if(c.moveToFirst()) 
      { 
     do 
     { 
       a = c.getInt(0); 
       b1 = c.getDouble(1); 
       c1 = c.getDouble(2); 
       e = c.getString(3);    
       f=c.getString(4); 

       results.add(e+"\n"+f); 

      } 
      while (c.moveToNext()); } 

      Myadapter adapter=new Myadapter(this, R.layout.row,R.id.text2, results); 


      lv.setBackgroundColor(Color.WHITE); 
      //lv.setTextFilterEnabled(true); 
      lv.setCacheColorHint(Color.WHITE); 
       lv.setAdapter(adapter); 

這裏R.id.text2是第二TextView中的ID添加值顯示活動代碼。 這裏是我在myadapter類代碼

public Myadapter(Context context, int resource, int textViewResourceId, 
      List<String> results) { 
     super(context, resource, textViewResourceId, results); 
     // TODO Auto-generated constructor stub 
     this.context=context; 
     this.results=results; 

    } 

    private List<String> results; 
Context context; 




    private static final String LayoutInflater = null; 

@Override 
    public View getView(final int position, View convertView, ViewGroup viewGroup) { 
      String name=results.get(position); 
      String address=results.get(position); 
      if (convertView == null) { 
       LayoutInflater inflater = (LayoutInflater) context 
       .getSystemService(Context.LAYOUT_INFLATER_SERVICE); 
       convertView = inflater.inflate(R.layout.row, null); 
      } 
      TextView tv11 = (TextView) convertView.findViewById(R.id.text11); 
      tv11.setText(name); 

      TextView text2 = (TextView) convertView.findViewById(R.id.text2); 
      text2.setText(address); 
    pls help me. here is the row.xml 
<?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:id="@+id/text11" 

     android:layout_alignParentLeft="true" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
    android:textSize="20sp" 
    android:textColor="#000000" 
     /> 


      <TextView 
     android:id="@+id/text2" 

     android:layout_alignParentLeft="true" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
    android:textSize="10sp" 
    android:textColor="#000000" 
     /> 

      <Button android:text="Delete" android:id="@+id/button1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:focusable="false" android:focusableInTouchMode="false" 
      ></Button> 
</LinearLayout> 

請幫助我,我想的名字出現在第二TextView的第一和地址。請幫助我。感謝和問候

+0

您是否可以通過在eclipse中使用靜態文本在圖形佈局中查看它來獲得所需的行佈局? – blessenm

+0

我在圖形佈局中獲得佈局。請告訴我如何在單獨的文字瀏覽中添加數組列表項目。我在單個文本視圖中獲取這兩個值 – hussain

回答

1

改變你的佈局

android:id="@+id/text2" 

    android:layout_alignParentRight="true" 
在你的第二個文本視圖

。您已將兩個文字瀏覽對齊到左側。如上所述更改第二個textview的對齊方式。但如果其中一個文本很大,你仍然會遇到重疊。