0
我使用ActionBar Sherlock並正常工作。setOnItemClickListener在自定義ListView中不工作ActionBarSherlock
這個代碼在2.x的罰款,但不是在4.x的
的點擊只能在2.x版本4.x版中的版本中沒有工作,我嘗試過很多辦法,我不能讓點擊功能
有什麼問題?
import java.util.ArrayList;
import android.app.Activity;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import android.widget.TextView;
import android.widget.Toast;
import com.actionbarsherlock.app.SherlockListActivity;
public class Inicio extends SherlockListActivity {
private ListView mListView;
private ArrayList<Capitulos> listado;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
mListView = getListView();
listado = new ArrayList<Capitulos>();
for(int i = 0; i < 20; i++){
listado.add(new Capitulos("Titulo " + i, "descripcion " + i));
}
AdaptadorTitulares adaptador = new AdaptadorTitulares(Inicio.this);
setListAdapter(adaptador);
mListView.setOnItemClickListener(new OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> a, View v, int position, long id) {
Toast.makeText(Inicio.this, "hazlo", 0).show();
}
});
}
class AdaptadorTitulares extends ArrayAdapter {
Activity context;
@SuppressWarnings("unchecked")
AdaptadorTitulares(Activity context) {
super(context, R.layout.lista, listado);
this.context = context;
}
public View getView(int position, View convertView, ViewGroup parent) {
LayoutInflater inflater = context.getLayoutInflater();
View item = inflater.inflate(R.layout.lista, null);
TextView titulo = (TextView)item.findViewById(R.id.titulo_art);
titulo.setText(((Capitulos)getItem(position)).getTitulo());
TextView subtitulo = (TextView)item.findViewById(R.id.desc_art);
subtitulo.setText(((Capitulos)getItem(position)).getDescrip());
return(item);
}
}
}
我已經嘗試,並沒有工作:( – user2379552 2013-05-13 23:18:24
可能有無關,與你的問題,但你爲什麼要定義新的'在'getView'中查看'('item')並且不會對'convertView'進行充氣? – 2013-05-14 09:58:33