Note that there are some explanatory texts on larger screens.

plurals
  1. POWork with dynamic elements from a custom adapter
    primarykey
    data
    text
    <p>Hellow this is my first question in stack. Im creating a dynamic grid of this tutorial <a href="http://www.stealthcopter.com/blog/2010/09/android-creating-a-custom-adapter-for-gridview-buttonadapter/comment-page-1/" rel="nofollow">http://www.stealthcopter.com/blog/2010/09/android-creating-a-custom-adapter-for-gridview-buttonadapter/comment-page-1/</a></p> <p>Now it's working pretty good. My layout is composed by a gridView and under this gridView i have a TextView.</p> <p>The problem is that i want to change the TextView to display different information on each id when the focus changes (on the grid elements). I've tried to use OnFocusChangeListener inside ButtonAdapter, but when trying to get a reference to the textView, it says that findViewById is not implemented.</p> <p>I wonder how to make a reference in my main activity that allows me to handle my dynamic grid elements. I have the following in onCreate();</p> <pre><code> GridView gridview = (GridView) findViewById(R.id.gridview); gridview.setAdapter(new ButtonAdapter(this)); </code></pre> <p>So i want to handle my grid elements from here, any ideas? Thanks</p> <p>Edit: I've been trying to change different things, but im receiving a NullPointerException from my getView method. I can't find a way to make it work, i'll apreciate any help guys, this is my code:</p> <pre><code> public View getView(int position, View convertView, ViewGroup parent) { final Button btn; if (convertView == null) { // if it's not recycled, initialize some attributes btn = new Button(mContext); btn.setLayoutParams(new GridView.LayoutParams(100, 55)); btn.setPadding(8, 8, 8, 8); } else { btn = (Button) convertView; } btn.setText(filenames[position]); // filenames is an array of strings btn.setTextColor(Color.WHITE); btn.setId(position); btn.setOnClickListener(new OnClickListener() { @Override public void onClick(View arg0) { TextView vt = (TextView) btn.findViewById(R.id.textView1); vt.setText("Button Pressed"); } }); </code></pre> <p>Thanks.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload