繰り返しのないアプリ名のリストを取得したいのですが、リストビューが既に同じ名前を持っていることをどのように知ることができますか?私は次のコードを試してみましたが、私は唯一のアプリケーションの複数のプロセスを実行しているので、私は唯一のもののためのアプリ名を表示したいこの状況で重複するアプリ名を取得しています。 どうすればいいですか?重複せずにお使いのデバイス内のすべてのパッケージ名を検索するためのListViewから重複したアプリ名(文字列)を削除します
@Override
public View getView(int position, View convertView, ViewGroup parent)
{
final ViewHolder holder;
if (null == convertView)
{
LayoutInflater layoutInflater = (LayoutInflater) m_oContext
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
convertView = layoutInflater.inflate(R.layout.list_item, null);
holder = new ViewHolder(convertView);
} else
{
holder = (ViewHolder) convertView.getTag();
}
AndroidAppProcess androidAppProcess = m_processesList.get(position);
//getItem(position);
TextView processName = (TextView) convertView.findViewById(R.id.name);
ImageView appIcon = (ImageView) convertView.findViewById(R.id.icon);
if (androidAppProcess != null)
{
try
{
String proName= (String) m_oContext.getPackageManager().getApplicationLabel(m_oContext.getPackageManager().getApplicationInfo(androidAppProcess.getPackageName(), m_oContext.getPackageManager().GET_META_DATA));
// if(processName !=null && !m_processesList.contains(proName))
if(processName !=null && !proName.equalsIgnoreCase((String)processName.getText()))
{
if(!proName.equals("Battery Optimizer"))
{
processName.setText(proName);
appIcon.setImageDrawable(m_oContext.getPackageManager().getApplicationIcon(androidAppProcess.getPackageName()));
}
}
//TODO: maintain icon size to avoid OOM error
} catch (PackageManager.NameNotFoundException e)
{
processName.setText(androidAppProcess.getPackageName());
Drawable res = m_oContext.getResources().getDrawable(R.mipmap.ic_launcher, m_oContext.getTheme());
appIcon.setImageDrawable(res);
}
}
スクリーンショットをしてください。 –
単純適用HashSetはあなたの問題を解決します –
@ S.W。それを解決することができますが、私はアダプタのgetView()の中でそれを使用する必要があります...あなたはそれを使用する方法を精巧にplzすることができます – sam