私のアプリでは、ユーザーがインストールしたすべてのアプリケーションのリストが、スライド ドロワーのリストビューに設定されています。ユーザーがリストビューからドロワーの他の領域 (ドロワーが引き出される領域) に 1 つのリンクをドラッグできるようにするにはどうすればよいでしょうか?
ドラッグアンドドロップを調べたところ、各アイテムにIDが必要であることに気付きました(各アイテムのIDを作成する方法がわかりません)。
とにかく、ここに私のコーディングがあります:
Drag_and_Drop_App:
package com.example.awesomefilebuilderwidget;
IMPORTS
public class Drag_and_Drop_App extends Activity {
private ListView mListAppInfo;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// set layout for the main screen
setContentView(R.layout.drag_and_drop_app);
// load list application
mListAppInfo = (ListView)findViewById(R.id.lvApps);
// create new adapter
AppInfoAdapter adapter = new AppInfoAdapter(this, Utilities.getInstalledApplication(this), getPackageManager());
// set adapter to list view
mListAppInfo.setAdapter(adapter);
// implement event when an item on list view is selected
mListAppInfo.setOnItemClickListener(new OnItemClickListener() {
@Override
public void onItemClick(AdapterView parent, View view, int pos, long id) {
// get the list adapter
AppInfoAdapter appInfoAdapter = (AppInfoAdapter)parent.getAdapter();
// get selected item on the list
ApplicationInfo appInfo = (ApplicationInfo)appInfoAdapter.getItem(pos);
// launch the selected application
Utilities.launchApp(parent.getContext(), getPackageManager(), appInfo.packageName);
}
});
}
}
バックグラウンドで実行してユーザー アプリケーションを収集し、onClickListners を実行する他のクラスがあることに注意してください。ただし、これが実際のウィジェットに表示されます。
Drag_and_Drop_App.xml は次のとおりです。
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<SlidingDrawer
android:id="@+id/bottom"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_centerVertical="true"
android:orientation="horizontal"
android:layout_marginTop="200dp"
android:content="@+id/content"
android:handle="@+id/handle" >
<Button
android:id="@+id/handle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Handle" />
<LinearLayout
android:id="@+id/content"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:background="#00FF00">
<ListView
android:id="@+id/lvApps"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
/>
</LinearLayout>
</SlidingDrawer>
</RelativeLayout>
リストビュー内のアイテムがロングクリックされたときに、ユーザーがそれをビューの他のセクションにドラッグアンドドロップできるように、おそらく OnLongClick リスナーを使用したいと思うでしょう。
また、リンク/アプリケーションがドロップされるビューは、DragListener を使用した 1 つの巨大なドロップ ターゲットになることも認識しています。(ここでドラッグアンドドロップに関するチュートリアルを見てきました
レイアウトで使用する割り当てられた LongTouchListener を持つことができるように、各リストビュー項目の ID を作成するにはどうすればよいですか?
これが理にかなっているといいのですが、そうでない場合はお知らせください!