난 당신이 아래의 일부 코드를 사용할 수있다, 그래서 화면의 유사한 종류를했다. 내 화면의
public class ListViewCustomAdapter extends BaseAdapter {
/**
* Array list to hold assets which need to be displayed
*/
ArrayList<Asset> itemList;
/**
* Context: Interface to global information about an application
* environment.
*/
public Activity context;
/**
* Layout inflater to inflate view of each row of the list from the layout
* xml
*/
public LayoutInflater inflater;
/**
* @param context
* : Context: Interface to global information about an
* application environment.
* @param itemList
* : arraylist to hold asset which need to be displayed in list
*/
public ListViewCustomAdapter(Activity context, ArrayList<Asset> itemList) {
super();
this.context = context;
this.itemList = itemList;
this.inflater = (LayoutInflater) context
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
}
// @Override
/*
* (non-Javadoc)
*
* @see android.widget.Adapter#getCount()
*/
public int getCount() {
if (itemList != null) {
return itemList.size();
}else return 0;
}
// @Override
/*
* (non-Javadoc)
*
* @see android.widget.Adapter#getItem(int)
*/
public Object getItem(int position) {
if(itemList != null){
return itemList.get(position);
}else{
return 0;
}
}
// @Override
/*
* (non-Javadoc)
*
* @see android.widget.Adapter#getItemId(int)
*/
public long getItemId(int position) {
return 0;
}
/**
* @author asadafale class to create view of each row in the list
*/
public static class ViewHolder {
/**
* displays name of asset
*/
TextView txtVw_name;
/**
* displays serial no of asset
*/
TextView txtVw_sno;
/**
* displays type of asset
*/
TextView txtVw_type;
}
// @Override
/*
* (non-Javadoc)
*
* @see android.widget.Adapter#getView(int, android.view.View,
* android.view.ViewGroup)
*/
public View getView(int position, View convertView, ViewGroup parent) {
ViewHolder holder;
if (convertView == null) {
holder = new ViewHolder();
convertView = inflater.inflate(R.layout.listview_row, null);
holder.txtVw_name = (TextView) convertView
.findViewById(R.id.tv_name);
holder.txtVw_sno = (TextView) convertView.findViewById(R.id.tv_sno);
holder.txtVw_type = (TextView) convertView
.findViewById(R.id.tv_type);
convertView.setTag(holder);
} else
holder = (ViewHolder) convertView.getTag();
// set selected item
LinearLayout activeItem = (LinearLayout) convertView;
if (position == SearchAssetActivity.selectedItem) {
activeItem.setBackgroundColor(Color.GRAY);
// for focus on it
int top = (activeItem == null) ? 0 : activeItem.getTop();
((ListView) parent).setSelectionFromTop(position, top);
} else {
activeItem.setBackgroundColor(Color.BLACK);
}
Asset bean = (Asset) itemList.get(position);
holder.txtVw_name.setText(bean.getAssetName());
holder.txtVw_sno.setText(bean.getSno());
holder.txtVw_type.setText(bean.getAssetType());
return convertView;
}
}
부분은 당신이 원하는처럼 비슷합니다.
다음은 XML로 내 레이아웃입니다 :
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/grey05"
android:orientation="horizontal" >
<TextView
android:id="@+id/tv_name"
android:layout_width="1dip"
android:layout_height="wrap_content"
android:layout_marginLeft="20dp"
android:layout_weight="0.25"
android:text="Name"
android:textAppearance="?android:attr/textAppearanceMedium" >
</TextView>
<TextView
android:id="@+id/tv_sno"
android:layout_width="1dip"
android:layout_height="wrap_content"
android:layout_weight="0.25"
android:text="Serial No."
android:textAppearance="?android:attr/textAppearanceMedium" >
</TextView>
<TextView
android:id="@+id/tv_type"
android:layout_width="1dip"
android:layout_height="wrap_content"
android:layout_weight="0.25"
android:layout_marginLeft="20dp"
android:text="Type"
android:textAppearance="?android:attr/textAppearanceMedium" >
</TextView>
</LinearLayout>
은 내가 3 열 만 표시 할 것을 알고 있었다. layout.xml에서 많은 텍스트 뷰를 정의 할 수 있습니다. 귀하의 경우에는 당신이 비행 중에 열의 수를 알 수 있다고 믿기 때문에 xml을 통해 동적으로 수행 할 수없는 일종의
TextView
배열이 필요합니다. 어댑터 클래스에
TextView
배열을 정의해야하며 데이터베이스에서 오는 데이터에 따라 초기화 할 수 있습니다. 내가 전달하고 싶었던 것이 있기를 바랍니다. 일단 당신이 시작하면, 그것을 설계하는 데 도움이 필요하면 알려주십시오. :)
문제 세부 사항 – sunil
무엇이 문제이고, 더 많은 정보를 게시하십시오. –
당신은 단지 textviews의 5 열을 가지고 gridview을 원해 ?? – AkashG