如何在列表视图中显示EditText项目点击android?

时间:2014-11-18 13:56:44

标签: android listview

我正在显示ListView中的网络列表,当我点击显示EditText要求password的项目时,我想要这样做。单击项目时,我无法在EditText上显示ListView。任何帮助将不胜感激。这是我的代码:

package com.example.scanwifi;
import java.net.DatagramSocket;
import java.net.SocketException;
import java.util.List;
import android.annotation.SuppressLint;
import android.app.Activity;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.net.wifi.ScanResult;
import android.net.wifi.WifiManager;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.ArrayAdapter;
import android.widget.EditText;
import android.widget.ListView;
import android.widget.Toast;
public class MainActivity extends Activity {
private ClientDatagramSender clientdatagramsender=null;
private DatagramSocket datagramsocket=null;
    EditText etpin; 
    WifiManager mainWifiObj;
    WifiScanReceiver wifiReciever;
    ListView list=null;
    String wifis[];
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        list = (ListView)findViewById(R.id.listview1);
        mainWifiObj = (WifiManager) getSystemService(Context.WIFI_SERVICE);
        wifiReciever = new WifiScanReceiver();
        mainWifiObj.startScan();
        list.setOnItemClickListener(new OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> arg0, View arg1, int arg2, long arg3) {
                // TODO Auto-generated method stub
                etpin = (EditText) findViewById(R.id.etPin);
                etpin.setVisibility(View.VISIBLE);

            }
        });
        try {
            datagramsocket=new DatagramSocket();
        } catch (SocketException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }

    }
    protected void onPause() {
        unregisterReceiver(wifiReciever);
        super.onPause();
    }
    protected void onResume() {
        registerReceiver(wifiReciever, new IntentFilter(
                WifiManager.SCAN_RESULTS_AVAILABLE_ACTION));
        super.onResume();
    }
    class WifiScanReceiver extends BroadcastReceiver {
        @SuppressLint("UseValueOf")
        public void onReceive(Context c, Intent intent) {
            List<ScanResult> wifiScanList = mainWifiObj.getScanResults();
            wifis = new String[wifiScanList.size()];
            for(int i = 0; i < wifiScanList.size(); i++){
                wifis[i] = ((wifiScanList.get(i)).toString());
            }
            list.setAdapter(new ArrayAdapter<String>(getApplicationContext(),
                    android.R.layout.simple_list_item_1,wifis));
        }
    }
}

1 个答案:

答案 0 :(得分:1)

您可以使用EditText(How to take text input with DialogFragment in Android?)启动DialogFragment,并且可以使用列表项单击来处理此对话框。

点击项目 - &gt;打开对话框询问密码 - &gt;从编辑文本返回密码 - &gt;做你想做的事。

如果要在listview项目中显示编辑文本,可以将项目设置为view.invisibly,并通过单击事件设置可见性。