Note that there are some explanatory texts on larger screens.

plurals
  1. POMake ListView item click to create new Intent with the JSON data
    primarykey
    data
    text
    <p>I want to create a new intent for each of the item in my ListView. But first I am trying to see if the data holder.title can be read through log. It cannot. I tried to use Toast, but I also receive error on makeText().</p> <p>What is wrong with my codes? I am not a java programmer, forgive me if this is a simple problem.</p> <p>This codes is based on the solution from <a href="https://stackoverflow.com/questions/14701747/how-to-parse-sub-jsonarray-and-display-image">How to parse Sub JSONArray and display image?</a></p> <p>I have modify some of the codes but I am confident enough that it should not affect this part of the code.</p> <pre><code>@Override public View getView(int position, View convertView, ViewGroup parent) { Data item = mObjects.get(position); View rowView = convertView; if (rowView == null) { LayoutInflater inflater = mActivity.getLayoutInflater(); rowView = inflater.inflate(R.layout.item, parent, false); ViewHolder viewHolder = new ViewHolder(); viewHolder.icon = (ImageView) rowView.findViewById(R.id.image); viewHolder.title = (TextView) rowView.findViewById(R.id.title); rowView.setTag(viewHolder); } ViewHolder holder = (ViewHolder) rowView.getTag(); holder.title.setText(item.getmTitle()); item.setOnClickListener(new OnItemClickListener() { public void onItemClick(AdapterView&lt;?&gt; parent, View v, int position, long id) { //Intent to be here. Now I am testing to see if data can be passed but it can't Log.e("log_tag","This is being clicked"); } }); holder.icon.setBackgroundResource(R.drawable.ic_launcher); holder.mTask = new DownloadImageTask(item.getmImageUrl(), holder.icon); if (!holder.mTask.isCancelled()) { holder.mTask.execute(); } return rowView; } </code></pre> <p>EDITED! I tried for hours for the codes above but it looks hopeless. So I look into the MainActivity class. And at least something came out. When i click the list item, "This is being clicked" is being showed. But i am still not able to show any of the JSON data upon clicking. And I am wondering how do i do intent from here.</p> <p>Edited Again.</p> <p>I change some code after seeing more codes online. And still stuck.</p> <pre><code>mListView = (ListView) findViewById(android.R.id.list); mAdapter = new Adapter(this, mSource); mListView.setAdapter(mAdapter); mListView.setOnItemClickListener(new OnItemClickListener() { //private Object title; @Override public void onItemClick(AdapterView&lt;?&gt; parent, View v, int position, long id) { @SuppressWarnings("unchecked") HashMap&lt;String, String&gt; o = (HashMap&lt;String, String&gt;) mListView.getItemAtPosition(position); //Selected item //String product = ((TextView) View).getText().toString(); Toast.makeText(getApplicationContext(),o.get("title"), Toast.LENGTH_LONG).show(); } }); </code></pre>
    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.
 

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