Android应用程序上未触发自定义适配器的setOnItemClickListener
我试图在用户单击某个项目时触发一个代码段。它在自定义适配器上触发,但在主网段上不触发 这是适配器的代码段,我正试图触发它,但它没有被触发Android应用程序上未触发自定义适配器的setOnItemClickListener,android,listview,onclick,adapter,Android,Listview,Onclick,Adapter,我试图在用户单击某个项目时触发一个代码段。它在自定义适配器上触发,但在主网段上不触发 这是适配器的代码段,我正试图触发它,但它没有被触发 public class Program_Lure_list_Adapter extends BaseAdapter implements View.OnClickListener { private static ArrayList<Program_Lure_Sound> programLureList; private LayoutInf
public class Program_Lure_list_Adapter extends BaseAdapter implements View.OnClickListener {
private static ArrayList<Program_Lure_Sound> programLureList;
private LayoutInflater l_inflater;
private int mPosition;
private int[] Image = {R.drawable.blacksound};
ViewHolder viewHolder;
ViewHolder selectedHolder;
private Activity activity;
public Program_Lure_list_Adapter(Activity a, ArrayList<Program_Lure_Sound> result) {
activity = a;
programLureList = result;
l_inflater = (LayoutInflater)activity.
getSystemService(Context.LAYOUT_INFLATER_SERVICE);
}
/*public Program_Lure_list_Adapter(Context context, ArrayList<Program_Lure_Sound> result) {
programLureList = result;
l_inflater = LayoutInflater.from(context);
}*/
@Override
public int getCount() {
return programLureList.size();
}
/*@Override
public Object getItem(int i) {
return null;
}*/
public Object getItem(int position) {
return position;
}
/*@Override
public long getItemId(int i) {
return 0;
}*/
public long getItemId(int position) {
return position;
}
@Override
public View getView(final int i, View view, ViewGroup viewGroup) {
if (view == null) {
view = l_inflater.inflate(R.layout.layout_programlure_listitem, viewGroup, false);
viewHolder = new ViewHolder();
viewHolder.iv_Image_souund = (ImageView) view.findViewById(R.id.imageView29);
viewHolder.tv_soundName = (TextView) view.findViewById(R.id.textView92);
viewHolder.tv_selected = (TextView) view.findViewById(R.id.textView_selected);
view.setTag(viewHolder);
} else
viewHolder = (ViewHolder) view.getTag();
viewHolder.iv_Image_souund.setImageResource(Image[programLureList.get(i).getSoundImage()]);
viewHolder.tv_soundName.setText(programLureList.get(i).getSoundName());
viewHolder.tv_selected.setVisibility(View.GONE);
view.setTag(viewHolder);
view.setOnClickListener(this);
return view;
}
@Override
public void onClick(final View v) {
v.post(new Runnable() {
@Override
public void run() {
ViewHolder holder = ((ViewHolder) v.getTag());
holder.tv_selected.setVisibility(View.VISIBLE);
if (selectedHolder != null)
selectedHolder.tv_selected.setVisibility(View.INVISIBLE);
selectedHolder = holder;
}
});
}
public class ViewHolder{
TextView tv_soundName;
ImageView iv_Image_souund;
TextView tv_selected;
}
private class OnItemClickListener implements OnClickListener{
private int mPosition;
OnItemClickListener(int position){
mPosition = position;
}
@Override
public void onClick(View arg0) {
Activity_program_lure sct = (Activity_program_lure)activity;
sct.onItemClick(mPosition);
}
}
公共类程序\u Lure\u list\u适配器扩展BaseAdapter实现View.OnClickListener{
私有静态ArrayList程序列表;
私人充气机;
私人投资;
private int[]Image={R.drawable.blacksound};
持票人持票人;
ViewHolder selectedHolder;
私人活动;
公共程序\u诱惑\u列表\u适配器(活动a,ArrayList结果){
活动=a;
程序列表=结果;
l_充气机=(充气机)活动。
getSystemService(上下文布局\充气机\服务);
}
/*公共程序\u Lure\u list\u适配器(上下文、ArrayList结果){
程序列表=结果;
l_inflater=从(上下文)开始的布局更平坦;
}*/
@凌驾
public int getCount(){
返回programLureList.size();
}
/*@凌驾
公共对象getItem(int i){
返回null;
}*/
公共对象getItem(int位置){
返回位置;
}
/*@凌驾
公共长getItemId(int i){
返回0;
}*/
公共长getItemId(int位置){
返回位置;
}
@凌驾
公共视图getView(最终int i、视图视图、视图组视图组){
如果(视图==null){
视图=l_充气机。充气(R.layout.layout_程序lure_列表项,视图组,false);
viewHolder=新的viewHolder();
viewHolder.iv_Image_sound=(ImageView)view.findViewById(R.id.imageView29);
viewHolder.tv_soundName=(TextView)view.findViewById(R.id.textView92);
viewHolder.tv_selected=(TextView)view.findViewById(R.id.TextView_selected);
view.setTag(viewHolder);
}否则
viewHolder=(viewHolder)view.getTag();
viewHolder.iv_Image_sound.setImageResource(Image[programLureList.get(i).getSoundImage());
viewHolder.tv_soundName.setText(programLureList.get(i).getSoundName());
viewHolder.tv_selected.setVisibility(View.GONE);
view.setTag(viewHolder);
view.setOnClickListener(这个);
返回视图;
}
@凌驾
公共void onClick(最终视图v){
v、 post(新的Runnable(){
@凌驾
公开募捐{
ViewHolder=((ViewHolder)v.getTag());
holder.tv_selected.setVisibility(视图可见);
如果(selectedHolder!=null)
selectedHolder.tv\U selected.setVisibility(视图.不可见);
selectedHolder=holder;
}
});
}
公共类视图持有者{
TextView tv_soundName;
ImageView iv_Image_sound;
已选择文本视图电视;
}
私有类OnItemClickListener实现OnClickListener{
私人投资;
OnItemClickListener(内部位置){
位置=位置;
}
@凌驾
公共void onClick(视图arg0){
Activity\u program\u lure sct=(Activity\u program\u lure)Activity;
sct.onItemClick(合成);
}
}
}
这是自定义适配器,onClick正确触发,但我还需要另一段来触发
if(getSoundList()!=null) {
final ArrayList<Program_Lure_Sound> plsList = getSoundList();
//mAdapter = new Program_Lure_list_Adapter(this, plsList);
mAdapter = new Program_Lure_list_Adapter(Activity_program_lure.this, plsList);
activeSoundList.setAdapter(mAdapter);
setListViewHeightBasedOnChildren(activeSoundList);
// activeSoundList.setAdapter();
// activeSoundList
activeSoundList.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
Log.v("BLEApp", "HEREHERE2");
String name = plsList.get(i).getSoundName();
String[] arr = name.split(" ");
String ID = arr[0].split("#")[1];
// soundCode = ID;
//showToast("Sound code: "+soundCode);
String sd = plsList.get(i).getSoundName();
if (sd.length() > 10)
sd = sd.substring(0, Math.min(sd.length(), 10));
tv_ActiveSound.setText(sd);
if (mBluetoothLeService != null) {
// playSound(ID);
try {
changeToSound(ID);
} catch (Exception e) {
e.printStackTrace();
}
} else {
showToast("Please, click on power button and then click to" +
"play sound...!");
}
}
});
// endregion
dbHelper = new DataBaseHelper(this);
String lureUsed = dbHelper.LureUsed(lureName);
dbHelper.closeDB();
tv_LureUsed.setText(lureUsed);
}
float opacity = 0.4f;
ll.setAlpha(opacity);
tv_power.setText("ON");
playSoundButton.setAlpha(opacity);
playSoundButton.setEnabled(false);
}
public void onItemClick(int mPosition) {
Log.v("BLEApp", "HEREHERE");
final ArrayList<Program_Lure_Sound> plsList = getSoundList();
int i=mPosition; String name = plsList.get(i).getSoundName();
String[] arr = name.split(" ");
String ID = arr[0].split("#")[1];
// soundCode = ID;
//showToast("Sound code: "+soundCode);
String sd = plsList.get(i).getSoundName();
if(sd.length()>10)
sd = sd.substring(0, Math.min(sd.length(),10));
tv_ActiveSound.setText(sd);
if(mBluetoothLeService!=null){
// playSound(ID);
try {
changeToSound(ID);
} catch (Exception e) {
e.printStackTrace();
}
} else{
showToast("Please, click on power button and then click to" +
"play sound...!");
}
}
if(getSoundList()!=null){
最终ArrayList plsList=getSoundList();
//mAdapter=新程序\诱惑\列表\适配器(此,plsList);
mAdapter=新程序\诱惑\列表\适配器(活动\计划\诱惑。此,plsList);
activeSoundList.setAdapter(mAdapter);
setListViewHeightBasedOnChildren(activeSoundList);
//activeSoundList.setAdapter();
//动态声音列表
activeSoundList.setOnItemClickListener(新的AdapterView.OnItemClickListener(){
@凌驾
公共无效onItemClick(AdapterView AdapterView、View视图、int i、long l){
Log.v(“BLEApp”、“here2”);
String name=plsList.get(i).getSoundName();
字符串[]arr=name.split(“”);
字符串ID=arr[0]。拆分(“#”)为[1];
//soundCode=ID;
//showToast(“声音代码:+声音代码”);
字符串sd=plsList.get(i).getSoundName();
如果(sd.length()>10)
sd=sd.substring(0,Math.min(sd.length(),10));
tv_ActiveSound.setText(sd);
if(mBluetoothLeService!=null){
//播放声音(ID);
试一试{
改变声音(ID);
}捕获(例外e){
e、 printStackTrace();
}
}否则{
showToast(“请单击电源按钮,然后单击以”+
“播放声音…!”;
}
}
});
//端区
dbHelper=新的DataBaseHelper(此);
字符串lureUsed=dbHelper.lureUsed(lureName);
dbHelper.closeDB();
tv_LureUsed.setText(LureUsed);
}
浮动不透明度=0.4f;
ll.setAlpha(不透明度);
tv_power.setText(“打开”);
playSoundButton.setAlpha(不透明度);
playSoundButton.setEnabled(假);
}
公共空间链接(集成){
Log.v(“BLEApp”,“此处”);
最终ArrayList plsList=getSoundList();
int i=mPosition;String name=plsList.get(i).getSoundName();
字符串[]arr=name.split(“”);
字符串ID=arr[0]。拆分(“#”)为[1];
//soundCode=ID;
//showToast(“声音代码:+声音代码”);
字符串sd=plsList.get(i).getSoundName();
如果(sd.length()>10)
sd=sd.substring(0,Math.min(sd.length(),10));
tv_ActiveSound.setText(sd);
if(mBluetoothLeService!=null){
//播放声音(ID);
试一试{
改变声音(ID);
}捕获(例外e){
e、 printStackTrace();
}
}否则{
showToast(“请单击电源按钮,然后单击以”+
“播放声音…!”;
}
}
有什么想法吗?我猜是索姆
mAdapter = new Program_Lure_list_Adapter(MainActivity.this, plsList);
private Activity activity;
public Program_Lure_list_Adapter(Activity a, ArrayList<Program_Lure_Sound> result) {
activity = a;
programLureList = result;
l_inflater = (LayoutInflater)activity.
getSystemService(Context.LAYOUT_INFLATER_SERVICE);
}
private class OnItemClickListener implements OnClickListener{
private int mPosition;
OnItemClickListener(int position){
mPosition = position;
}
@Override
public void onClick(View arg0) {
MainActivity sct = (MainActivity)activity;
sct.onItemClick(mPosition);
}
}
public Object getItem(int position) {
return position;
}
public long getItemId(int position) {
return position;
}
String[] arr = name.split(" ");
String ID = arr[0].split("#")[1];
// soundCode = ID;
//showToast("Sound code: "+soundCode);
String sd = plsList.get(i).getSoundName();
if(sd.length()>10)
sd = sd.substring(0, Math.min(sd.length(),10));
tv_ActiveSound.setText(sd);
if(mBluetoothLeService!=null){
// playSound(ID);
try {
changeToSound(ID);
} catch (Exception e) {
e.printStackTrace();
}
} else{
showToast("Please, click on power button and then click to" +
"play sound...!");
}
}