2017-10-08 10 views
1

携帯電話でapkファイルをリストビューで表示するアプリを作成しています。私はこのアプリケーションでListActivityを使用しています。リストビューで行を選択すると、強調表示され、apkファイルに対応するアプリケーションが開きます。アプリケーションを開く必要はありません。行を選択しても強調表示されないようにしますその他のアクション。私は
を使ってみました(ただし、ここでは動作しません)。
2. android:choiceMode="singleChoice"(再び動作していない)
3. getListView().setChoiceMode(ListView.CHOICE_MODE_SINGLE);(作業が、クリックでアプリを開きます)
私はそれがしたい、行はいくつかの時間後に強調表示されないようにしますクリックして&がハイライト表示されて強調表示され、アプリを開くことは望ましくない。どうすればいいですか?選択された行アイテムがListActivityでハイライト表示されたままにする

AllAppsActivity.java

public class AllAppsActivity extends ListActivity { 
    private PackageManager packageManager = null; 
    private List<ApplicationInfo> applist = null; 
    private ApplicationAdapter listadaptor = null; 

    @Override 
    public void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 
     setContentView(R.layout.activity_apk); 

     packageManager = getPackageManager(); 

     new LoadApplications().execute(); 

     getListView().setChoiceMode(ListView.CHOICE_MODE_SINGLE); 
     getListView().setSelector(android.R.color.darker_gray); 
    } 

    @Override 
    protected void onListItemClick(ListView l, View v, int position, long id) { 
     super.onListItemClick(l, v, position, id); 

     ApplicationInfo app = applist.get(position); 
     try { 
      Intent intent = packageManager 
        .getLaunchIntentForPackage(app.packageName); 

      if (null != intent) { 
       startActivity(intent); 
      } 
     } catch (ActivityNotFoundException e) { 
      Toast.makeText(AllAppsActivity.this, e.getMessage(), 
        Toast.LENGTH_LONG).show(); 
     } catch (Exception e) { 
      Toast.makeText(AllAppsActivity.this, e.getMessage(), 
        Toast.LENGTH_LONG).show(); 
     } 
    } 

    private List<ApplicationInfo> checkForLaunchIntent(List<ApplicationInfo> list) { 
     ArrayList<ApplicationInfo> applist = new ArrayList<ApplicationInfo>(); 
     for (ApplicationInfo info : list) { 
      try { 
       if (null != packageManager.getLaunchIntentForPackage(info.packageName)) { 
        applist.add(info); 
       } 
      } catch (Exception e) { 
       e.printStackTrace(); 
      } 
     } 

     return applist; 
    } 

    private class LoadApplications extends AsyncTask<Void, Void, Void> { 
     private ProgressDialog progress = null; 

     @Override 
     protected Void doInBackground(Void... params) { 
      applist = checkForLaunchIntent(packageManager.getInstalledApplications 
        (PackageManager.GET_META_DATA)); 
      listadaptor = new ApplicationAdapter(AllAppsActivity.this, 
        R.layout.snippet_list_row, applist); 

      return null; 
     } 

     @Override 
     protected void onCancelled() { 
      super.onCancelled(); 
     } 

     @Override 
     protected void onPostExecute(Void result) { 
      setListAdapter(listadaptor); 
      progress.dismiss(); 
      super.onPostExecute(result); 
     } 

     @Override 
     protected void onPreExecute() { 
      progress = ProgressDialog.show(AllAppsActivity.this, null, 
        "Loading application info..."); 
      super.onPreExecute(); 
     } 

     @Override 
     protected void onProgressUpdate(Void... values) { 
      super.onProgressUpdate(values); 
     } 
    } 
} 

activity_apk.xml

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

    <ImageButton 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:src="@drawable/btn_playlist" /> 

    <ListView 
     android:id="@android:id/list" 
     android:layout_width="fill_parent" 
     android:layout_height="fill_parent" 
     android:divider="#242424" 
     android:dividerHeight="1dp" 
     /> 


</LinearLayout> 
+0

こちらの回答をご覧ください。 https://stackoverflow.com/a/46474418/3145960 –

+0

[Recycler View:特定の時間間隔の後にリサイクルビューアイテム(行)をハイライト表示させたい](https://stackoverflow.com/questions/) 46273492/recycler-view-i-want-my-recycler-view-item-specific-after-highlight-after-specific) –

+0

しばらくして項目を強調したくない@ReazMurshed、それはどのように重複していますか? – Amelia

答えて

0

あなたは何もしない場合は何もしません。 onListItemClickメソッドをオーバーライドしないでください(削除してください)、それだけです。

+0

私はそれがクリックで強調表示されるようにしたい、それは私が欲しいものです。何もない – Amelia

+0

それは自動的に表示されます –

+0

?コードなしで? – Amelia

0

アダプターBeanにフラグを定義し、アダプターのフラグでハイライトを設定し、フラグを変更してitemをクリックするとadapter.notifyDataSetChanged()を変更します。

関連する問題