Tôi cần một số trợ giúp để thực hiện một cú nhấp chuột đơn giản trong một mục listview để mở Hoạt động mới. Tôi đã thấy rất nhiều vấn đề này ở đây nhưng không ai giúp tôi.bắt đầu hoạt động mới trên mục danh sách nhấp chuột
public class CustomListView extends ListActivity {
private EfficientAdapter adap;
...
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);
setContentView(R.layout.main);
adap = new EfficientAdapter(this);
setListAdapter(adap);
}
@Override
protected void onListItemClick(ListView l, View v, int position, long id) {
// TODO Auto-generated method stub
super.onListItemClick(l, v, position, id);
startActivity(new Intent(CustomListView.this, next.class));
}
public static class EfficientAdapter extends BaseAdapter implements Filterable {
private LayoutInflater mInflater;
private Bitmap mIcon1;
private Context context;
public EfficientAdapter(Context context) {
// Cache the LayoutInflate to avoid asking for a new one each time.
mInflater = LayoutInflater.from(context);
this.context = context;
}
public View getView(final int position, View convertView, ViewGroup parent) {
ViewHolder holder;
if (convertView == null) {
convertView = mInflater.inflate(R.layout.adaptor_content, null);
convertView.setOnClickListener(new OnClickListener() {
private int pos = position;
@Override
public void onClick(View v) {
}
});
convertView.setTag(holder);
}else{
// Get the ViewHolder back to get fast access to the TextView
// and the ImageView.
holder = (ViewHolder) convertView.getTag();
}
return convertView;
}
...
}
}
tôi đã cố gắng cũng thêm mã tiếp theo bên trong của phương pháp onCreate từ lớp CustomListView nhưng nó không hoạt động hoặc
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) {
startActivity(new Intent(CustomListView.this, next.class));
}
});
"Nó không hoạt động" rất mơ hồ ... Điều gì xảy ra trong ví dụ đầu tiên khi bạn nhấp vào một mục? Bạn có nhận được bất kỳ lỗi nào không? Xin vui lòng gửi chúng nếu bạn làm. – Sam
@DDjordjevic: 'one' như thế nào trong' one.this' mà bạn truyền vào phương thức khởi tạo 'Intent'? Hãy thử 'CustomListView.this'. – Squonk