Skip to main content

Android Listview With Clickable different view






in Main Activity Class :

package com.example.test;
import java.io.IOException;
import java.io.InputStream;
import java.net.HttpURLConnection;
import java.net.URL;
import java.util.ArrayList;
import android.app.Activity;
import android.app.ProgressDialog;
import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Color;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.util.Log;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.ListView;
import android.widget.TextView;
import android.widget.Toast;
public class MainActivity extends Activity {

    String iMages[] = {
            "http://www.thebiblescholar.com/android_awesome.jpg",
            "http://blogs-images.forbes.com/rogerkay/files/2011/07/Android1.jpg",
            "http://cdn.slashgear.com/wp-content/uploads/2012/10/android-market-leader-smartphone.jpg",
            "http://www.planmyworkshop.com/images/android.jpeg",
            "http://www.androidguys.com/wp-content/uploads/2012/07/01-android2.jpg" };
    String text[] = { "one", "two", "theree", "four", "five" };

    ArrayList<Bitmap> bitmap_array = new ArrayList<Bitmap>();
    private ListView listv;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        listv = (ListView) findViewById(R.id.listView1);

        final ProgressDialog progDailog = new ProgressDialog(MainActivity.this);
        final Handler handler = new Handler() {

            public void handleMessage(Message msg) {

                listv.setAdapter(new ListViewAdapter_test(MainActivity.this));
            }
        };
        new Thread() {

            public void run() {

                for (int i = 0; i < iMages.length; i++) {
                    Log.d("i-->" + i, "Url-->" + iMages[i]);
                    Bitmap bit = getBitmapFromURL(iMages[i]);
                    bitmap_array.add(bit);
                }

                progDailog.dismiss();
                handler.sendEmptyMessage(0);

            }
        }.start();

    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        getMenuInflater().inflate(R.menu.activity_main, menu);
        return true;
    }

    public class ListViewAdapter_test extends BaseAdapter {

        private LayoutInflater mInflater;

        public ListViewAdapter_test(Context con) {
            // TODO Auto-generated constructor stub
            mInflater = LayoutInflater.from(con);
        }

        public int getCount() {
            // TODO Auto-generated method stub
            return iMages.length;
        }

        public Object getItem(int position) {
            // TODO Auto-generated method stub

            return position;
        }

        public long getItemId(int position) {
            // TODO Auto-generated method stub

            return position;
        }

        public View getView(final int position, View convertView,
                ViewGroup parent) {
            // TODO Auto-generated method stub
            final ListContent holder;
            View v = convertView;
            if (v == null) {
                v = mInflater.inflate(R.layout.row, null);
                holder = new ListContent();

                holder.name = (TextView) v.findViewById(R.id.textView1);

                holder.button = (Button) v.findViewById(R.id.button1);

                holder.img_p = (ImageView) v.findViewById(R.id.imageView1);

                v.setTag(holder);
            } else {

                holder = (ListContent) v.getTag();
            }

            holder.name.setText(text[position]);
            holder.button.setText(text[position]);

            if (bitmap_array.get(position) != null) {
                holder.img_p.setImageBitmap(bitmap_array.get(position));
            } else {
                holder.img_p.setImageDrawable(getResources().getDrawable(
                        R.drawable.ic_launcher));
            }

            holder.button.setOnClickListener(mOnTitleClickListener_button);

            holder.img_p.setOnClickListener(mOnTitleClickListener_image);

            return v;
        }
    }

    static class ListContent {

        ImageView img_p;

        TextView name;

        Button button;

    }

    public OnClickListener mOnTitleClickListener_image = new OnClickListener() {
        public void onClick(View v) {
            final int position = listv.getPositionForView((View) v.getParent());

            ImageView i = new ImageView(MainActivity.this);
            i.setImageBitmap(bitmap_array.get(position));

            Toast toastView = new Toast(MainActivity.this);
            toastView.setView(i);
            toastView.setDuration(Toast.LENGTH_LONG);
            toastView.setGravity(Gravity.CENTER, 0, 0);
            toastView.show();

            Log.d("you are click on image view", "you are click on image view");

        }
    };

    public OnClickListener mOnTitleClickListener_button = new OnClickListener() {
        public void onClick(View v) {
            final int position = listv.getPositionForView((View) v.getParent());

            Log.d("you are click on image view", "you are click on image view");

            Toast.makeText(MainActivity.this,
                    "click on button " + text[position], Toast.LENGTH_LONG)
                    .show();

        }
    };

    public static Bitmap getBitmapFromURL(String src) {
        try {
            URL url = new URL(src);
            HttpURLConnection connection = (HttpURLConnection) url
                    .openConnection();
            connection.setDoInput(true);
            connection.connect();
            InputStream input = connection.getInputStream();
            Bitmap myBitmap = BitmapFactory.decodeStream(input);
            return myBitmap;
        } catch (IOException e) {
            e.printStackTrace();
            return null;
        }
    }
}


activity_main.xml



<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:orientation="vertical" >

        <ListView
            android:id="@+id/listView1"
            android:layout_width="match_parent"
            android:layout_height="wrap_content" >
        </ListView>

    </LinearLayout>

row.xml
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent" >

    <ImageView
        android:id="@+id/imageView1"
        android:layout_width="100dp"
        android:layout_height="100dp"
        android:src="@drawable/ic_launcher" />

    <TextView
        android:id="@+id/textView1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="hello"
        android:textAppearance="?android:attr/textAppearanceLarge" />

    <Button
        android:id="@+id/button1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="click me" />
</LinearLayout>
android manifest file :
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.example.test"
    android:versionCode="1"
    android:versionName="1.0" >

    <uses-sdk
        android:minSdkVersion="8"
        android:targetSdkVersion="15" />
    <uses-permission android:name="android.permission.INTERNET"/>
    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>

    <application
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name"
        android:theme="@style/AppTheme" >
        <activity
            android:name=".MainActivity"
            android:label="@string/title_activity_main" >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
    </application>
</manifest>

Comments

Popular posts from this blog

MCP vs CLI: Which One Fits Your AI Agent's Job?

  Every AI agent that touches the outside world does it one of two ways: it runs a shell command, or it calls a tool through the Model Context Protocol. Both get the job done, but they don't cost the same or fail the same way, which is why "MCP vs CLI" keeps resurfacing without resolving. I want to answer it for the cases that matter most: plain developer tooling, data-heavy systems like banking, forecasting pipelines, and transaction automation like billing or booking. Neither wins outright. Where you draw the line is the actual skill. Key Takeaways CLI is the default for anything the model already knows cold, git, file ops, text processing, since there's no schema tax and commands chain through pipes. MCP earns its cost when a system needs per-user auth, audit trails, or access to sources the model can't otherwise reach, exactly what regulated systems like banking require. Transaction automation works best split: deterministic code drives the repeatable steps, a...

ANDROID - Adding ActionBar Navigation Tabs

Note: if you are develop App < 3.0 Android OS then use  ActionBarSherlock   support library. ActionBarSherlock is an extension of the  support library  designed to facilitate the use of the action bar design pattern across all versions of Android with a single API. Create new Android Project : in Main Activity package com.AlarmManager; import android.os.Bundle; import android.view.View; import com.actionbarsherlock.app.ActionBar; import com.actionbarsherlock.app.ActionBar.Tab; import com.actionbarsherlock.app.SherlockFragmentActivity; public class AlarmManagerActivity extends SherlockFragmentActivity { public static String ACTIVE_TAB = "activeTab"; /** Called when the activity is first created. */ @Override public void onCreate(Bundle savedInstanceState) { setTheme(R.style.Theme_Sherlock_Light_DarkActionBar); super.onCreate(savedInstanceState); // s...

Don't Ship AI Agent Skills Without Evals

At the AI Engineer World's Fair on July 1, 2026, Philipp Schmid, a Staff Engineer on the Gemini API and agents team at Google DeepMind, asked a room full of engineers a simple question: who uses skills with their coding agents? Every hand went up. Who has evals for those skills? Almost none. That gap is the entire talk, which Schmid also wrote up on his own blog, philschmid.de/testing-skills . His team indexed the skills ecosystem through SkillsBench and found the same pattern everywhere: people ship a SKILL.md file after two manual test runs and move on. It looks fine in a demo. It quietly corrupts outputs in production, because bad skills don't crash. They just make the agent confidently wrong. If you've already read our breakdown of Matt Pocock's Claude Code skills library , think of this as the other half of that story: what happens once you've installed a skill and it's actually running against real prompts. Key Takeaways SkillsBench indexed 47,000+ un...