0
我在尋找某種方式排點擊行被點擊時
時,我一直在使用吹氣佈局與列表適配器可從視圖中獲得的文字,但我提起來解決這個問題,得到的文本內容。
我試圖用:
public class LastDaysAdapter extends ArrayAdapter<LastDaysHelper>{
private final Activity activity;
List<LastDaysHelper> busIDs = new ArrayList<LastDaysHelper>();
List<LastDaysHelper> Dates = new ArrayList<LastDaysHelper>();
Context context;
public LastDaysAdapter(Activity activity,List<LastDaysHelper> list, Context context2, List<LastDaysHelper> list2){
super(activity, R.layout.activity_last_days,list);
this.activity=activity;
this.busIDs=list;
this.Dates=list2;
this.context=context2;
}
class ViewHolder {
protected TextView palteNumber;
protected TextView LastDate;
protected TableRow row;
;
}
@Override
public View getView(final int position, View convertView, ViewGroup parent) {
View view = null;
if (convertView == null) {
LayoutInflater inflator = activity.getLayoutInflater();
view = inflator.inflate(R.layout.rep, null);
ViewHolder viewHolder = new ViewHolder();
viewHolder.palteNumber = (TextView) view
.findViewById(R.id.TextView1);
viewHolder.LastDate = (TextView) view
.findViewById(R.id.textView2);
viewHolder.row = (TableRow) view.findViewById(R.id.TableRow05);
view.setTag(viewHolder);
viewHolder.row.setTag(busIDs.get(position));
} else{
view = convertView;
((ViewHolder) view.getTag()).row.setTag(busIDs
.get(position));
}
final ViewHolder holder = (ViewHolder) view.getTag();
holder.palteNumber.setText(busIDs.get(position).getDate());
holder.LastDate.setText(Dates.get(position).getDate());
return view;
}
}
編輯我已經嘗試使用這樣的:
public class LastDaysActivity extends ListActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_last_days);
final Button newFourm = (Button) findViewById(R.id.button1);
LastDaysAdapter adapter = new LastDaysAdapter(this, getDates(),
getApplicationContext(), getBusID());
setListAdapter(adapter);
newFourm.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
Intent i = new Intent(LastDaysActivity.this,
TabHostActivity.class);
startActivity(i);
}
});
}
@Override
protected void onListItemClick(ListView l, View v, int position, long id) {
String item = (String) getListAdapter().getItem(position);
Toast.makeText(this, item + " selected", Toast.LENGTH_LONG).show();
}
public List<LastDaysHelper> getDates() {
final MySQLiteHelper my = new MySQLiteHelper(LastDaysActivity.this);
return my.getDates();
}
public List<LastDaysHelper> getBusID() {
final MySQLiteHelper my = new MySQLiteHelper(LastDaysActivity.this);
return my.getBuses();
}
}
代碼示例,請 – user3245658
就在編輯它 –
增加了一個很好的措施。 –