Note that there are some explanatory texts on larger screens.

plurals
  1. POAndroid - onClick in adapter not working
    primarykey
    data
    text
    <p>Scenario: </p> <p>User clicks a button and a row(adapter) is added. The user inputs a value and clicks on a button which is generated. The value would be computed and displayed in an edit text. </p> <p>Problem: The value is not computed nor is it being displayed in the edit text. What am I doing wrong?</p> <p>custom_list_item.xml</p> <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt; &lt;LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical" android:layout_width="fill_parent" android:layout_height="wrap_content"&gt; &lt;LinearLayout android:orientation="horizontal" android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_marginTop="10dp" android:gravity="center"&gt; &lt;EditText android:id="@+id/name" android:layout_width="125dp" android:layout_height="wrap_content" android:hint="Name" android:maxLength="10" /&gt; &lt;EditText android:id="@+id/price" android:layout_width="80dp" android:layout_height="wrap_content" android:hint="Price" android:inputType="numberDecimal" android:maxLength="5" /&gt; &lt;Button android:id="@+id/calculate" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Calculate" /&gt; &lt;/LinearLayout&gt; &lt;EditText android:id="@+id/result" android:layout_width="150dp" android:layout_height="wrap_content" android:layout_gravity="center_horizontal" android:editable="false" android:cursorVisible="false" android:text="$0.00" /&gt; </code></pre> <p></p> <p>main.java <code>&lt;&lt;EDITTED&gt;&gt;</code></p> <pre><code>public class AdvancedBillSplitter extends Activity{ ArrayList&lt;String&gt; noteList = new ArrayList&lt;String&gt;(); FancyAdapter aa = null; Button calculate; //EditText price; EditText result; public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); ListView myListView = (ListView)findViewById(R.id.noteList); aa = new FancyAdapter(); myListView.setAdapter(aa); myListView.setOnItemClickListener(new OnItemClickListener() { public void onItemClick(AdapterView&lt;?&gt; arg0, View arg1, int position, long arg3) { EditText price = (EditText)findViewById(R.id.price); price = (EditText)findViewById(R.id.price); double price1 = Double.parseDouble(price.getText().toString()); double total = price1 *1.1; String resultPrice = Double.toString(total); result.setText(resultPrice); System.out.println(total); } }); aa.notifyDataSetChanged(); Button btnSimple = (Button)findViewById(R.id.btnSimple); btnSimple.setOnClickListener(new OnClickListener() { public void onClick(View v) { noteList.add(0, ""); aa.notifyDataSetChanged(); } }); } class FancyAdapter extends ArrayAdapter&lt;String&gt; { Button calculate; EditText price; EditText result; FancyAdapter() { super(AdvancedBillSplitter.this, android.R.layout.simple_list_item_1, noteList); } public View getView(int position, View convertView, ViewGroup parent) { View row = convertView; if(row == null) { LayoutInflater inflater = getLayoutInflater(); row = inflater.inflate(R.layout.custom_list_item, null); } return (row); } } } </code></pre>
    singulars
    1. This table or related slice is empty.
    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.
 

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