Note that there are some explanatory texts on larger screens.

plurals
  1. POPass data from main activity to base adapter one
    primarykey
    data
    text
    <p>I would like to pass the value of editText1.getText().toString() to the base adapter one in order to compare this value with "num". ¿How can I do it?</p> <p>Here are my 2 activities:</p> <p>public class MyActivity extends Activity {</p> <pre><code>private ListView mList; private ArrayList&lt;String&gt; arrayList; private MyCustomAdapter mAdapter; private TCPClient mTcpClient; private Double comp; String info; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); final EditText editText1 = (EditText) findViewById(R.id.editText1); editText1.setOnKeyListener(new OnKeyListener() { @Override public boolean onKey(View arg0, int arg1, KeyEvent arg2) { if (arg1 == KeyEvent.KEYCODE_ENTER){ Toast.makeText( editText1.getContext() , "Write: " + editText1.getText().toString() , Toast.LENGTH_SHORT) .show(); return true; } return false; } }); double comp=Double.parseDouble(editText1.getText().toString()); arrayList = new ArrayList&lt;String&gt;(); //relate the listView from java to the one created in xml mList = (ListView)findViewById(R.id.list); mAdapter = new MyCustomAdapter(this, arrayList, comp); mList.setAdapter(mAdapter); // connect to the server new connectTask().execute(""); } public class connectTask extends AsyncTask&lt;String,String,TCPClient&gt; { @Override protected TCPClient doInBackground(String... message) { //we create a TCPClient object and mTcpClient = new TCPClient(new TCPClient.OnMessageReceived() { @Override //here the messageReceived method is implemented --&gt;TCPClient.java public void messageReceived(String message) { //this method calls the onProgressUpdate publishProgress(message); } }); mTcpClient.run(); return null; } @Override protected void onProgressUpdate(String... values) { super.onProgressUpdate(values); //in the arrayList we add the messaged received from server arrayList.add(values[0]); // notify the adapter that the data set has changed. This means that new message received // from server was added to the list mAdapter.notifyDataSetChanged(); } } </code></pre> <p>}</p> <p>public class MyCustomAdapter extends BaseAdapter {</p> <pre><code>private ArrayList&lt;String&gt; mListItems; private LayoutInflater mLayoutInflater; private Double comp; public MyCustomAdapter(Context context, ArrayList&lt;String&gt; arrayList, Double compa){ mListItems = arrayList; comp = compa; //get the layout inflater mLayoutInflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE); } @Override public int getCount() { //getCount() represents how many items are in the list return mListItems.size(); } @Override //get the data of an item from a specific position //i represents the position of the item in the list public Object getItem(int i) { return null; } @Override //get the position id of the item from the list public long getItemId(int i) { return 0; } @Override public View getView(int position, View view, ViewGroup viewGroup) { //check to see if the reused view is null or not, if is not null then reuse it if (view == null) { view = mLayoutInflater.inflate(R.layout.list_item, null); } //get the string item from the position "position" from array list to put it on the TextView String stringItem = mListItems.get(position); if (stringItem != null) { TextView itemName = (TextView) view.findViewById(R.id.list_item_text_view); if (itemName != null) { //set the item name on the TextView itemName.setText(stringItem); double num=Double.parseDouble(stringItem); if (num&gt;comp) { itemName.setText(stringItem); } else { itemName.setBackgroundColor(Color.BLUE); itemName.setText(stringItem); } } } //this method must return the view corresponding to the data at the specified position. return view; } </code></pre> <p>}</p>
    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.
 

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