问题描述:

i am trying to display the application name and icon using the base adapter to the list in activity 1 as follows.

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<?> 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);

}

});

}

}

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. HERE I WANT TO DISPLAY THE PACKAGE NAME OF THE SELECTED APPLICATION NAME.

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);

}

}

baseadapter

public class ListAdapter extends BaseAdapter {

private static ListAdapter self = null;

private Context context = null;

private List<MyAppInfo> 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<MyAppInfo>();

generate();

}

private void generate() {

PackageManager pm = context.getPackageManager();

List<ApplicationInfo> packages = pm

.getInstalledApplications(PackageManager.GET_META_DATA);

for (ApplicationInfo applicationInfo : packages) {

if ((applicationInfo.flags & 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;

}

}

相关阅读:
Top