0

リストに表示されているアプリを選択し、それらのいずれかを選択するとダイアログが表示され、その特定のアプリに関連付けられているパスコードを入力するようにユーザーに促し、パスコードをデータベース「mysqlite」に保存したいと思います"

以下は私のコードであり、これを達成するために私が持っているコードに何を変更/追加する必要があるかを知りたいですか?

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" >

    <ListView
        android:id="@+id/listapps"
        android:layout_width="match_parent"
        android:layout_height="wrap_content" >
    </ListView>

</RelativeLayout>

ジャバ:

package com.example.androidproject;

import java.util.ArrayList;
import java.util.List;

import android.os.Bundle;
import android.app.Activity;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.content.pm.ResolveInfo;
import android.util.Log;
import android.view.Menu;
import android.widget.ArrayAdapter;
import android.widget.ListView;

public class PasscodeLock extends Activity {
    private ListView lView;
    private ArrayList results;
    List<ResolveInfo> list;
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_passcode_lock);

        results = new ArrayList();
        lView = (ListView) findViewById(R.id.listapps);
        PackageManager pm = this.getPackageManager();

        Intent intent = new Intent(Intent.ACTION_MAIN, null);
        intent.addCategory(Intent.CATEGORY_LAUNCHER);

        list = pm.queryIntentActivities(intent, PackageManager.PERMISSION_GRANTED);
        for (ResolveInfo rInfo : list) 
        {
            results.add(rInfo.activityInfo.applicationInfo.loadLabel(pm).toString());
            Log.w("Installed Applications", rInfo.activityInfo.applicationInfo.loadLabel(pm).toString());
        }
        lView.setAdapter(new ArrayAdapter(this, android.R.layout.simple_list_item_1, results));
    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) 
    {
        getMenuInflater().inflate(R.menu.activity_passcode_lock, menu);
        return true;
    }
}
4

1 に答える 1

0

First of all, it appears to me that you have populated the list with lView.setAdapter, but you have not actually added the function that allows the User Selection to be selected.

And another thing is, it is usually preferred for the activity to be ListActivity instead of Activity, but of course that would depend on the implementation, because you might not have a fullscreen ListView.

Nonetheless, you can add an OnItemClickListener like this :

public class PasscodeLock extends Activity implements OnItemClickListener(){
   ....
}

which will trigger you to add another function called onItemClick, in which you will add the code to call the dialog which prompts the User to enter the passcode

public void onItemClick(AdapterView<?> arg0, View arg1, int arg2, long arg3) {
   //call dialog
}

With regard to how to create that dialog I am not that sure as the dialogs I created are just to show messages to the user.

于 2013-01-22T09:57:21.070 に答える