As stated in the gridview the item plus button, button button click event where the item is the toast of the position, but after my program to run in addition to the first item on the button the other button can be normal toast, the question now is Click on the first item of the button does not respond, then click the other button normal toast after toast the button first button events, heroes seek help, the next grateful
Reply:
Add that development api version I use is 4.0.3, if willing to learn more about the discussion add me qq 969298114
Reply:
Starting from 0. . . . You are not writing from a beginning. . .
Reply:
I use BaseAdapter, getview in the default position is to start from zero, and I have not changed
Reply:
Paste the code look
Reply:
package com.www.testlifale;
import java.util.ArrayList;
import java.util.List;
import android.app.AlertDialog;
import android.app.ProgressDialog;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.graphics.Color;
import android.os.Handler;
import android.os.Message;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.View.OnClickListener;
import android.widget.BaseAdapter;
import android.widget.Button;
import android.widget.RelativeLayout;
import android.widget.TextView;
import android.widget.Toast;
/ **
* Use the list of cached past Item
*
* @ Author hellogv
*
* /
public class CacheAdapter extends BaseAdapter {
private Context mContext;
private ArrayList
private LayoutInflater inflater;
private Thread th;
public static ProgressDialog dialog;
private int id;
public CacheAdapter (Context c, ArrayList
mContext = c;
this.mItems = mItems;
inflater = (LayoutInflater) mContext
. GetSystemService (Context.LAYOUT_INFLATER_SERVICE);
}
public void addItem (String itemTitle, String name, int type) {
mItems.add (new Item (itemTitle, name, type));
}
public int getCount () {
return mItems.size ();
}
public Item getItem (int position) {
return mItems.get (position);
}
public long getItemId (int position) {
return position;
}
List
List
List
public View getView (int position, View convertView, ViewGroup parent) {
if (lstPosition.contains (position) == false) {
if (lstPosition.size ()> 75) / / where to set the cache Item number
{
lstPosition.remove (0) ;/ / delete
firstlstView.remove (0) ;/ / delete
first}
convertView = inflater.inflate (R.layout.gv_item, null);
final RelativeLayout rl = (RelativeLayout) convertView
. FindViewById (R.id.rl_zong);
final TextView text = (TextView) convertView
. FindViewById (R.id.tv_name);
final Button btn_kaitai = (Button) convertView
. FindViewById (R.id.btn_kaitai);
btn_kaitai.setTag (position);
final Button btn_close = (Button) convertView
. FindViewById (R.id.btn_close);
final Button btn_pingjia = (Button) convertView
. FindViewById (R.id.btn_pingjia);
final Button btn_service = (Button) convertView
. FindViewById (R.id.btn_service);
switch (mItems.get (position). getType ()) {
case 0 :/ / Founding
btn_kaitai.setVisibility (View.GONE);
btn_close.setVisibility (View.VISIBLE);
btn_pingjia.setVisibility (View.GONE);
btn_service.setVisibility (View.VISIBLE);
text.setText ("hairdresser:". + mItems.get (position) getName ());
rl.setBackgroundColor (Color.GREEN);
break;
case 1 :/ / Not Founding
btn_kaitai.setVisibility (View.VISIBLE);
btn_close.setVisibility (View.GONE);
btn_pingjia.setVisibility (View.INVISIBLE);
btn_service.setVisibility (View.GONE);
text.setText (mItems.get (position) getItemTitle ().);
rl.setBackgroundColor (Color.WHITE);
break;
case 2 :/ / wait state
evaluationbtn_kaitai.setVisibility (View.GONE);
btn_close.setVisibility (View.VISIBLE);
btn_service.setVisibility (View.GONE);
btn_pingjia.setVisibility (View.VISIBLE);
text.setText (mItems.get (position) getName ().);
rl.setBackgroundColor (Color.GREEN);
break;
default:
break;
}
btn_kaitai.setOnClickListener (new OnClickListener () {
@ Override
public void onClick (View v) {
Toast.makeText (mContext, "Founding" + btn_kaitai.getTag (), Toast.LENGTH_SHORT) show ();.
}
});
btn_pingjia.setOnClickListener (new OnClickListener () {
@ Override
public void onClick (View v) {
}
});
btn_service.setOnClickListener (new OnClickListener () {
@ Override
public void onClick (View v) {
}
});
btn_close.setOnClickListener (new OnClickListener () {
@ Override
public void onClick (View v) {
}
});
lstPosition.add (position) ;/ / add new items
lstView.add (convertView) ;/ / add new items
} Else {
convertView = lstView.get (lstPosition.indexOf (position));
final RelativeLayout rl = (RelativeLayout) convertView
. FindViewById (R.id.rl_zong);
final TextView text = (TextView) convertView
. FindViewById (R.id.tv_name);
final Button btn_kaitai = (Button) convertView
. FindViewById (R.id.btn_kaitai);
/ / Btn_kaitai.setTag (position);
final Button btn_close = (Button) convertView
. FindViewById (R.id.btn_close);
final Button btn_pingjia = (Button) convertView
. FindViewById (R.id.btn_pingjia);
final Button btn_service = (Button) convertView
. FindViewById (R.id.btn_service);
switch (mItems.get (position). getType ()) {
case 0 :/ / Founding
btn_kaitai.setVisibility (View.GONE);
btn_close.setVisibility (View.VISIBLE);
btn_pingjia.setVisibility (View.GONE);
btn_service.setVisibility (View.VISIBLE);
text.setText ("hairdresser:". + mItems.get (position) getName ());
rl.setBackgroundColor (Color.GREEN);
break;
case 1 :/ / Not Founding
btn_kaitai.setVisibility (View.VISIBLE);
btn_close.setVisibility (View.GONE);
btn_pingjia.setVisibility (View.INVISIBLE);
btn_service.setVisibility (View.GONE);
text.setText (mItems.get (position) getItemTitle ().);
rl.setBackgroundColor (Color.WHITE);
break;
case 2 :/ / wait state
evaluationbtn_kaitai.setVisibility (View.GONE);
btn_close.setVisibility (View.VISIBLE);
btn_service.setVisibility (View.GONE);
btn_pingjia.setVisibility (View.VISIBLE);
text.setText (mItems.get (position) getName ().);
rl.setBackgroundColor (Color.GREEN);
break;
default:
break;
}
btn_kaitai.setOnClickListener (new OnClickListener () {
@ Override
public void onClick (View v) {
/ / TODO Auto-generated method stub
Toast.makeText (mContext, "Founding" + btn_kaitai.getTag (), Toast.LENGTH_SHORT) show ();.
}
});
btn_pingjia.setOnClickListener (new OnClickListener () {
@ Override
public void onClick (View v) {
/ / TODO Auto-generated method stub
}
});
btn_service.setOnClickListener (new OnClickListener () {
@ Override
public void onClick (View v) {
/ / TODO Auto-generated method stub
}
});
btn_close.setOnClickListener (new OnClickListener () {
@ Override
public void onClick (View v) {
/ / TODO Auto-generated method stub
new AlertDialog.Builder (mContext)
. SetTitle ("Exit")
. SetMessage ("Are you sure you forced to close?")
. SetCancelable (false)
. SetPositiveButton ("OK",
new DialogInterface.OnClickListener () {
public void onClick (
DialogInterface dialog,
int which) {
}
.}) SetNegativeButton ("Cancel", null) show ();.
}
});
}
return convertView;
}
}
Code is a reference to the online heroes write, I write relatively long-winded Pleased to meet you
Reply:
Now the main problem btn_pingjia button, the other is negligible
Reply:
A man running on a real machine is not the case, I would not be on the pid
Reply:
I also encountered the same problem, click on the other item, the first item click event to respond, the problem gridview control it, the landlord solved?
Reply:
Dude, did you solve this problem. .
I have encountered, I do not know Zaban.
android gridview's item click the first button did not respond, click the button before the other item on the implementation of the first item of the button event
Reply:
How no solution ah?
Reply:
I have encountered this problem, I do not know what the reason is, but it can be solved, the btn click event can be transferred to the gridview, gridview.setOnItemClickListener (listener);
Reply:
Why btn_kaitai.setOnClickListener to register twice, will not be btn_kaitai.getTag () when you do not get to the value?
No comments:
Post a Comment