नहीं भेजा जा रहा है मेरे पास एक कस्टम बटन है, जिस पर मैं इसे टचवेन्ट पर कब्जा कर रहा हूं।एंड्रॉइड: कस्टम बटन ऑनक्लिक लिस्टनर को
public class CustomNumber extends ToggleButton {
boolean drawGlow = false;
float glowX = 0;
float glowY = 0;
float radius = 30;
public CustomNumber(Context context) {
super(context);
}
public CustomNumber(Context context, AttributeSet attrs) {
super(context, attrs);
}
public CustomNumber(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
}
Paint paint = new Paint();
{
paint.setAntiAlias(true);
paint.setColor(Color.WHITE);
paint.setAlpha(70);
};
@Override
public void draw(Canvas canvas){
super.draw(canvas);
if(drawGlow)
canvas.drawCircle(glowX, glowY, radius, paint);
}
@Override
public boolean onTouchEvent(MotionEvent event){
if(event.getAction() == MotionEvent.ACTION_DOWN){
drawGlow = true;
}else if(event.getAction() == MotionEvent.ACTION_UP)
drawGlow = false;
}
glowX = event.getX();
glowY = event.getY();
this.invalidate();
return true;
}
यह कस्टम बटन ग्रिड का हिस्सा है। जब मैं ग्रिड में यह बटन जोड़ रहा हूं, तो मैंने इसे ऑनक्लिक लिस्टनर सेट कर दिया है। लेकिन, OnClickListener में कोड कभी नहीं बुलाया जाता है।
GridAdapter कोड है, जहां मैं श्रोता के साथ बटन जोड़ने हूँ:
public View getView(final int position, final View convertView, final ViewGroup parent) {
CustomNumber tBtn;
if (convertView == null) {
tBtn = new CustomNumber(context);
tBtn.setTextOff("");
tBtn.setTextOn("");
tBtn.setChecked(false);
tBtn.setId(position);
tBtn.setOnClickListener(tBtnListener);
tBtn.setLayoutParams(new GridView.LayoutParams(35, 35));
} else {
tBtn = (CustomNumber) convertView;
}
return tBtn;
}
कृपया मदद करते हैं।
ओवरराइड नहीं कर रहे हैं यदि मैं ऑन टचवेन्ट कोड को हटा देता हूं, तो ऑनक्लिकलिस्टर कोड काम करता है। दोनों घटनाओं को एक साथ संभाला नहीं जा सकता ??? कृपया सहायता कीजिए! – Pria
निश्चित नहीं है लेकिन अंत में आप अपने टच में सच या गलत लौटते हैं या नहीं? –
मैंने onTouchEvent() से झूठी वापसी करने की कोशिश की। यह काम नहीं करता है :(आगे, यह घटना को मोशनएवेंट के रूप में लेता है। ACTION_DOWN हमेशा – Pria