Drag and drop d'une grid à une autre
Bonjour à toutes et à tous,
Voila longtemps que je n'étais pas bloqué sur une application Android donc c'est à mon tour de vous demander de l'aide ;)
Je suis entrain de programmer un effet de Drag and Drop d'une grid à une autre. Le problème ... je n'y arrive pas :(
Ma première grid est rempli. J'aimerai que lorsque je clique longtemps sur celle-ci je puisse le déplacer dans ma deuxième grid et l'ajouter à celle ci.
Il existe beaucoup d'exemple sur internet mais je programme en 2.X et non en 3.X ce qui pose problème.
Un peu de code:
Mon .xml:
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35
|
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<TextView
android:id="@+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Drag and drop applications to enable them:"
android:textAppearance="?android:attr/textAppearanceMedium" />
<GridView
android:id="@+id/griddrag"
android:layout_width="match_parent"
android:layout_height="300sp"
android:numColumns="3" >
</GridView>
<TextView
android:id="@+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Drop here:"/>
<GridView
android:id="@+id/griddrop"
android:layout_width="match_parent"
android:layout_height="300sp"
android:numColumns="3" >
</GridView>
</LinearLayout> |
Et mon activité:
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56
|
package com.webtiss.android;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import android.app.Activity;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.content.pm.ResolveInfo;
import android.os.Bundle;
import android.widget.GridView;
public class DragAndDropAndroidActivity extends Activity
{
/** Called when the activity is first created. */
@Override
public void onCreate (Bundle savedInstanceState)
{
super.onCreate (savedInstanceState);
setContentView (R.layout.main);
GridView gridAllApp = (GridView) findViewById (R.id.griddrag);
PackageManager manager = getPackageManager ();
Intent mainIntent = new Intent (Intent.ACTION_MAIN, null);
mainIntent.addCategory (Intent.CATEGORY_LAUNCHER);
final List<ResolveInfo> apps = manager.queryIntentActivities (
mainIntent, 0);
Collections
.sort (apps, new ResolveInfo.DisplayNameComparator (manager));
if (apps != null)
{
int count = apps.size ();
// liste des applications autorisees
ArrayList<ApplicationInfo> applicationsAuto = new ArrayList<ApplicationInfo> ();
for (int i = 0; i < count; i++)
{
ResolveInfo info = apps.get (i);
ApplicationInfo application = new ApplicationInfo ();
application.title = info.loadLabel (manager);
application.icon = info.activityInfo.loadIcon (manager);
applicationsAuto.add (application);
}
gridAllApp.setAdapter (new ApplicationsAdapter (this,
applicationsAuto, getLayoutInflater ()));
gridAllApp.setSelection (0);
}
}
} |
ApplicationAdapter étends un ArrayAdapter<ApplicationInfo> rien de bien compliqué. Chaque item de la grille est composé d'une icone et d'un textView.
Seriez vous comment faire pour créer l'effet dans une application 2.X?
Merci à tous ;)