Note that there are some explanatory texts on larger screens.

plurals
  1. POAndroid - Show textview by clicking on listview item
    text
    copied!<p>I am creating my very first Android application, but i stuck unfortunately. The application would be very simple: On the starting page there is a ListView with items like: 1st group 2nd group 3rd group ...</p> <p>By clicking on any of these items a new page would show up with a single textview element that would have some description. Like you click on '1st group' item, the listview gets hidden, and a new page appears with '1st group description' text.</p> <p>So far I can show the listview with the items, but when I click on them, nothing happens (i guess I miss some basic stuff, but as a very newby, i cannot find it out easily).</p> <pre><code>import java.util.ArrayList; import java.util.Arrays; import android.app.Activity; import android.os.Bundle; import android.widget.AdapterView; import android.widget.AdapterView.OnItemClickListener; import android.widget.ArrayAdapter; import android.widget.LinearLayout; import android.widget.LinearLayout.LayoutParams; import android.widget.ListView; import android.widget.TextView; import android.view.*; public class SimpleListViewActivity extends Activity { LinearLayout.LayoutParams layoutParams; LinearLayout ll; private ListView mainListView ; private ArrayAdapter&lt;String&gt; listAdapter ; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); // Find the ListView resource. mainListView = (ListView) findViewById( R.id.mainListView ); // populate the List of groups String[] GROUP = getResources().getStringArray(R.array.group); ArrayList&lt;String&gt; GrList = new ArrayList&lt;String&gt;(); GrList.addAll( Arrays.asList(GROUP) ); // Create ArrayAdapter using the list. listAdapter = new ArrayAdapter&lt;String&gt;(this, R.layout.simplerow, GrList); // Set the ArrayAdapter as the ListView's adapter. mainListView.setAdapter( listAdapter ); ll = (LinearLayout)findViewById(R.id.LinearLayout); layoutParams = new LinearLayout.LayoutParams (LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT); mainListView.setOnItemClickListener(new OnItemClickListener() { public void onItemClick(AdapterView&lt;?&gt; parent, View view, int position, long id) { TextView t = (TextView) findViewById(R.id.textView1); String[] DESC = getResources().getStringArray(R.array.desc); t.setText(DESC[position]); ll.addView(t); //This is the point that is wrong for sure (and others maybe also). I cannot get the textview shown } }); } } </code></pre> <p>Thanks for your help.</p>
 

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