大家好我在我的應用程序中顯示多列listview(列表有3列),但在我的應用程序中它顯示所有列相同的vaue。我的列表視圖佈局是這樣的:所有列在多列列表視圖中顯示相同的數據
<?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"
android:paddingBottom="5dip"
android:paddingLeft="5dip"
android:paddingTop="5dip" >
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:weightSum="3" >
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="2dip"
android:layout_marginRight="2dip"
android:layout_weight="1"
android:background="@drawable/listbackground"
android:gravity="center"
android:orientation="vertical" >
<TextView
android:id="@+id/Name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="#C20000"
android:textSize="14sp"
android:textStyle="bold" />
<TextView
android:id="@+id/ltp"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="2dip"
android:layout_marginRight="2dip"
android:layout_weight="1"
android:gravity="center"
android:orientation="horizontal" >
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_centerVertical="true"
android:src="@drawable/down" />
<TextView
android:id="@+id/perChange"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</LinearLayout>
</LinearLayout>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="2dip"
android:layout_marginRight="2dip"
android:layout_weight="1"
android:background="@drawable/listbackground"
android:gravity="center"
android:orientation="vertical" >
<TextView
android:id="@+id/Name1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="#C20000"
android:textSize="14sp"
android:textStyle="bold" />
<TextView
android:id="@+id/ltp1"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="2dip"
android:layout_marginRight="2dip"
android:layout_weight="1"
android:gravity="center"
android:orientation="horizontal" >
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_centerVertical="true"
android:src="@drawable/down" />
<TextView
android:id="@+id/perChange1"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</LinearLayout>
</LinearLayout>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="2dip"
android:layout_marginRight="2dip"
android:layout_weight="1"
android:background="@drawable/listbackground"
android:gravity="center"
android:orientation="vertical" >
<TextView
android:id="@+id/Name2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="#C20000"
android:textSize="14sp"
android:textStyle="bold" />
<TextView
android:id="@+id/ltp2"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="2dip"
android:layout_marginRight="2dip"
android:layout_weight="1"
android:gravity="center"
android:orientation="horizontal" >
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_centerVertical="true"
android:src="@drawable/down" />
<TextView
android:id="@+id/perChange2"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</LinearLayout>
</LinearLayout>
</LinearLayout>
final ListView lv = (ListView) findViewById(R.id.srListView);
lv.setAdapter(new MyCustomBaseAdapter(this, searchResults));
public class MyCustomBaseAdapter extends BaseAdapter {
private ArrayList<SearchResults> searchArrayList;
private LayoutInflater mInflater;
public MyCustomBaseAdapter(Context context,
ArrayList<SearchResults> results) {
searchArrayList = results;
mInflater = LayoutInflater.from(context);
}
public int getCount() {
return searchArrayList.size();
}
public Object getItem(int position) {
return searchArrayList.get(position);
}
public long getItemId(int position) {
return position;
}
public View getView(int position, View convertView, ViewGroup parent) {
ViewHolder holder;
if (convertView == null) {
convertView = mInflater.inflate(R.layout.custom_row_view, null);
holder = new ViewHolder();
holder.txtName = (TextView) convertView
.findViewById(R.id.Name);
holder.txtCityState = (TextView) convertView
.findViewById(R.id.ltp);
holder.txtPhone = (TextView) convertView
.findViewById(R.id.perChange);
holder.txtName1 = (TextView) convertView
.findViewById(R.id.Name1);
holder.txtCityState1 = (TextView) convertView
.findViewById(R.id.ltp1);
holder.txtPhone1 = (TextView) convertView
.findViewById(R.id.perChange1);
holder.txtName2 = (TextView) convertView
.findViewById(R.id.Name2);
holder.txtCityState2 = (TextView) convertView
.findViewById(R.id.ltp2);
holder.txtPhone2 = (TextView) convertView
.findViewById(R.id.perChange2);
convertView.setTag(holder);
} else {
holder = (ViewHolder) convertView.getTag();
}
System.out.println("position::" + position);
holder.txtName
.setText(searchArrayList.get(position).getStockCode());
holder.txtCityState.setText(searchArrayList.get(position).getLtp());
holder.txtPhone.setText(searchArrayList.get(position)
.getPerChange());
holder.txtName1.setText(searchArrayList.get(position)
.getStockCode());
holder.txtCityState1
.setText(searchArrayList.get(position).getLtp());
holder.txtPhone1.setText(searchArrayList.get(position)
.getPerChange());
holder.txtName2.setText(searchArrayList.get(position)
.getStockCode());
holder.txtCityState2
.setText(searchArrayList.get(position).getLtp());
holder.txtPhone2.setText(searchArrayList.get(position)
.getPerChange());
return convertView;
}
class ViewHolder {
TextView txtName;
TextView txtCityState;
TextView txtPhone;
TextView txtName1;
TextView txtCityState1;
TextView txtPhone1;
TextView txtName2;
TextView txtCityState2;
TextView txtPhone2;
}
}
這表明我輸出
現在,這裏顯示了所有列相同的數據,但我要的是展現所有列的不同數據,如何做到這一點?任何幫助/建議將不勝感激,提前致謝。
謝謝山姆,但現在有問題,如果名稱爲大,那麼我的輸出看起來像:假設維沙爾成爲Vishalllllllllllllllllllll
我建議簡化您的佈局一個盒子和使用GridView。 – Sam
使用gridview而不是列表視圖 – njzk2
我可以在gridview中的那個框中使用三行嗎?如果是,你可以向我展示任何示例/教程。謝謝 – PPD