Note that there are some explanatory texts on larger screens.

plurals
  1. POAndroid base adapter on item click i want to retrieve the package name belongs to the application label in the next activity
    text
    copied!<p>i am trying to display the application name and icon using the base adapter to the list in activity 1 as follows.</p> <pre><code>public class MainActivity extends Activity { private static final String TAG_Name = "name"; private static final String TAG_Logo = "logo"; @SuppressLint("NewApi") @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); TextView i = (TextView) findViewById(R.id.textView1); ListAdapter mAdapter = ListAdapter.getInstance(); mAdapter.setAdapterData(this.getApplicationContext()); final ListView listView = (ListView) findViewById(R.id.my_list); listView.setAdapter(mAdapter); mAdapter.notifyDataSetChanged(); i.setText(String.valueOf(ListAdapter.getInstance().getCount())); listView.setOnItemClickListener(new OnItemClickListener() { @Override public void onItemClick(AdapterView&lt;?&gt; parent, View view, int position, long id) { // TODO Auto-generated method stub String a = ((TextView) view.findViewById(R.id.text)).getText() .toString(); int n = position; Bitmap bitmap = ((BitmapDrawable)((ImageView) view.findViewById(R.id.image)) .getDrawable()).getBitmap(); // Starting new intent Intent in = new Intent(getApplicationContext(), Application_Perm.class); in.putExtra(TAG_Name, a); in.putExtra(TAG_Logo, bitmap); in.putExtra("TAG", n); startActivity(in); } }); } } </code></pre> <p>But what i do not know is, when i want to display the package name in the activity 2. which i pass the on select application name and icon. <strong>HERE I WANT TO DISPLAY THE PACKAGE NAME OF THE SELECTED APPLICATION NAME.</strong></p> <pre><code>public class Application_Perm extends Activity { private static final String TAG_Name = "name"; private static final String TAG_Logo = "logo"; String name; TextView pack; public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.perm); ImageView image = (ImageView) findViewById(R.id.logo); TextView app = (TextView) findViewById(R.id.textpermapp); pack = (TextView) findViewById(R.id.pa_info); Intent intent = getIntent(); name = intent.getStringExtra(TAG_Name); Bitmap bitmap = (Bitmap) this.getIntent().getParcelableExtra(TAG_Logo); app.setText(name); image.setImageBitmap(bitmap); } } </code></pre> <p><strong>baseadapter</strong></p> <pre><code>public class ListAdapter extends BaseAdapter { private static ListAdapter self = null; private Context context = null; private List&lt;MyAppInfo&gt; list = null; private LayoutInflater mInflater = null; private ListAdapter() { } public static ListAdapter getInstance() { if (self == null) { self = new ListAdapter(); } return self; } public synchronized void setAdapterData(Context context) { this.context = context; mInflater = LayoutInflater.from(this.context); list = new ArrayList&lt;MyAppInfo&gt;(); generate(); } private void generate() { PackageManager pm = context.getPackageManager(); List&lt;ApplicationInfo&gt; packages = pm .getInstalledApplications(PackageManager.GET_META_DATA); for (ApplicationInfo applicationInfo : packages) { if ((applicationInfo.flags &amp; ApplicationInfo.FLAG_SYSTEM) != 1) { list.add(new MyAppInfo("" + applicationInfo.loadLabel(pm), applicationInfo.loadIcon(pm))); } } } public synchronized int getCount() { return list.size(); } @Override public Object getItem(int position) { return list.get(position); } @Override public long getItemId(int position) { return position; } @Override public View getView(int position, View convertView, ViewGroup parent) { if (convertView == null) { convertView = mInflater.inflate(R.layout.list_item, parent, false); } MyAppInfo info = list.get(position); TextView text = (TextView) convertView.findViewById(R.id.text); ImageView image = (ImageView) convertView.findViewById(R.id.image); text.setText(info.appName); image.setImageDrawable(info.icon); return convertView; } } </code></pre>
 

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