0

我在一个活动中安装了应用程序,我有另一个活动,它仅列出在第一个活动中检查的应用程序。存在三个问题:拳头是不是在第二个活动中显示了这样的东西 你好

它显示这样的应用程序,而不是它们的名称和图标。我能为此做些什么?

其次,您可以看到它显示重复项。我没有任何复选框,所以如果在第一个活动中选择了两次应用程序,我不知道如何删除该应用程序

第三,我正在使用它来启动上图中选择的活动

    Intent newIntent = getPackageManager().getLaunchIntentForPackage(getPackageName());
    startActivity(newIntent);

它刚刚开始我的第一个活动。我需要在 getPackageName() 的空间中写什么?

如果需要,我将发布第一个和第二个活动的代码。谢谢。

这是我的 AppInfoAdapter

public class AppInfoAdapter extends BaseAdapter {
private Context mContext;
private List<?> mListAppInfo;
private PackageManager mPackManager;

public AppInfoAdapter(Context c, List<?> list, PackageManager pm) {
    mContext = c;
    mListAppInfo = list;
    mPackManager = pm;
}

@Override
public int getCount() {
    return mListAppInfo.size();
}

@Override
public Object getItem(int position) {
    return mListAppInfo.get(position);
}

@Override
public long getItemId(int position) {
    return position;
}

@Override
public View getView(int position, View convertView, ViewGroup parent) {
    // get the selected entry
    ApplicationInfo entry = (ApplicationInfo) mListAppInfo.get(position);

    // reference to convertView
    View v = convertView;

    // inflate new layout if null
    if(v == null) {
        LayoutInflater inflater = LayoutInflater.from(mContext);
        v = inflater.inflate(R.layout.lvrowlayout, null);
    }

    // load controls from layout resources
    ImageView ivAppIcon = (ImageView)v.findViewById(R.id.ivIcon);
    TextView tvAppName = (TextView)v.findViewById(R.id.tvName);
    TextView tvPkgName = (TextView)v.findViewById(R.id.tvPack);

    // set data to display
    ivAppIcon.setImageDrawable(entry.loadIcon(mPackManager));
    tvAppName.setText(entry.loadLabel(mPackManager));
    tvPkgName.setText(entry.packageName);

    // return view
    return v;
  }

这里是lvrowlayout

 <LinearLayout
 xmlns:android="http://schemas.android.com/apk/res/android"
 android:layout_width="fill_parent"
 android:layout_height="?android:attr/listPreferredItemHeight"
 android:padding="5dip" 
 >

<ImageView
  android:id="@+id/ivIcon"
  android:layout_width="wrap_content"
  android:layout_height="fill_parent"
  android:layout_marginRight="5dip"
  android:scaleType="center"
/>

<LinearLayout
  android:orientation="vertical"
  android:layout_width="0dip"
  android:layout_height="fill_parent"
  android:layout_weight="1"    
 >

  <TextView
      android:id="@+id/tvName"
      android:layout_width="fill_parent"
      android:layout_height="0dip"
      android:layout_weight="1"
      android:gravity="center_vertical"         
  />

  <TextView
      android:id="@+id/tvPack"
      android:layout_width="fill_parent"
      android:layout_height="0dip"
      android:layout_weight="1"
      android:singleLine="true"
      android:ellipsize="marquee"         
  />

  </LinearLayout>


</LinearLayout>
4

1 回答 1

0

你在使用 ListView 吗?你能发布你的适配器吗?似乎您没有覆盖 ListView 的适配器计数或可以设置图片的布局等。

您可以像这样为行创建布局

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="horizontal" >

    <ImageView
     .... />

    <TextView
     .... />

</LinearLayout>

然后在您的 ListView 适配器中

@Override
public View getView(final int position, View convertView, ViewGroup parent) {
        View v = convertView;
        LayoutInflater vi  (LayoutInflater)getActivity().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        v = vi.inflate(R.layout.custom_row, null);

//Set image and text view here

}
于 2013-07-12T18:59:54.673 回答