0

I have a list with TextViews, and when the user clicks a button I do a performClick() on the corresponding TextView (to trigger an QuickAction), but the view I get is null, does anyone know why this is, and how to fix this?

This is how I create the TextView

//The holder of a store, which contains a TextView
public List<Store> stores = new ArrayList<Store>();

// Create TextView and QuickAction within loop in method createStores();
FrameLayout.LayoutParams lp = new FrameLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
lp.leftMargin = Math.round(location[0]);
lp.topMargin = Math.round(location[1]);
lp.gravity = Gravity.TOP | Gravity.LEFT;

TextView tv = new TextView(getContext());
tv.setTag(s);
tv.setLayoutParams(lp);
tv.setText(s.name);

final QuickAction quickAction = new QuickAction(getContext(), QuickAction.VERTICAL);
ActionItem nextItem = new ActionItem(s.ID, s.name, null, s.ID);
quickAction.addActionItem(nextItem);

tv.setOnClickListener(new OnClickListener() {
    public void onClick(View v) {
        quickAction.show(v, null);  
    }
});

s.textview = tv;

Then, I have a search method, where I find a store from the stores List and want to simulate a click by the performClick() method. The OnClickListener is called, but the QuickAction is wrong placed because the TextView is null

// Then from another function
s.textview.performClick();

==== UPDATE ===== I solved my own problem, thanx everybody for helping!

user1393817
  • 294
  • 1
  • 3
  • 12
  • 2
    can u post the code and Log, where u got this problem...??? – Android Boy Jun 13 '12 at 07:30
  • please add logcat error message – ariefbayu Jun 13 '12 at 08:01
  • There is no error message, the tv.setOnClickListener is called and the QuickAction is shown, the only problem is that my view I get in onClick(View v) is null, so the QuickAction is at a wrong position – user1393817 Jun 13 '12 at 08:05
  • `the only problem is that my view I get in onClick(View v) is null` << this doesn't produce error? *weird* – ariefbayu Jun 13 '12 at 08:10
  • Sorry, correction, the view is not null, but this view is used in the QuickAction as an achor to position the QuickAction. It gets the position by anchor.getLocationOnScreen(location); But this location returns 0,0 – user1393817 Jun 13 '12 at 08:26

2 Answers2

1

I solved this: the problem was that I did the performClick while the view was not ready. So I added a delay like this to solve it:

s.textview.postDelayed(new Runnable() {
                                public void run() {
                                    s.textview.performClick();
                                }
                            }, 300);
user1393817
  • 294
  • 1
  • 3
  • 12
0
*tvlike.setTag(""+groupPosition);
            tvlike.setOnClickListener(new OnClickListener() {
                @Override
                public void onClick(View v) {
                    // TODO Auto-generated method stub

                    int position=Integer.parseInt(v.getTag().toString());*
                //...........use this position and get your data
Dara Saini
  • 293
  • 1
  • 3
  • 15