applicationinfo 中获取的class name是空的
老师,我想通过使用applicaitoninfo中的class name和package name来通过使用componentname来实现软件的跳转,但是我获取的class name是空的
package com.example.jeremychen.assignment4_2;
import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
import android.content.pm.ApplicationInfo;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;
import java.util.List;
/**
* Created by jeremychen on 2018/5/23.
*/
public class AppAdapter extends BaseAdapter {
private List<ApplicationInfo> appList;
private Context context;
public AppAdapter(List<ApplicationInfo> list, Context context) {
this.appList = list;
this.context = context;
}
@Override
public int getCount() {
return appList.size();
}
@Override
public Object getItem(int position) {
return appList.get(position);
}
@Override
public long getItemId(int position) {
return (long)position;
}
@Override
public View getView(final int position, View convertView, ViewGroup parent) {
LayoutInflater inflater = LayoutInflater.from(context);
convertView = inflater.inflate(R.layout.content_layout,null);
ImageView imageView = (ImageView) convertView.findViewById(R.id.imageView);
TextView textView = (TextView) convertView.findViewById(R.id.App_textview);
imageView.setImageDrawable(appList.get(position).loadIcon(context.getPackageManager()));
textView.setText(appList.get(position).loadLabel(context.getPackageManager()));
convertView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
String Package_name = appList.get(position).packageName;
String Class_name = appList.get(position).;
ComponentName componentName = new ComponentName(Package_name, Class_name);
Intent intent = new Intent();
intent.setComponent(componentName);
context.startActivity(intent);
}
});
return convertView;
}
public void refresh(List<ApplicationInfo> list)
{
appList = list;
notifyDataSetChanged();
}
}
这是我的adaptor类中使用了点击监听!!
正在回答 回答被采纳积分+1
String Class_name = appList.get(position).;
这里是我粘贴的问题, 实际上是下面的这种情况,问题依然是class name获取的为空值!
String Class_name = appList.get(position).name;
- 参与学习 人
- 提交作业 147 份
- 解答问题 687 个
本专题介绍了Android开发核心组件:广播、服务及全局应用。教会你如何使用AIDL、Thread、Socket、蓝牙解决进程线程间通信问题。利用Glide等实现异步加载及NDK原生代码开发。
了解课程
恭喜解决一个难题,获得1积分~
来为老师/同学的回答评分吧
0 星