Java 单击ListView中的select项时,不会发生任何事情,但LogCat中不会出现错误

Java 单击ListView中的select项时,不会发生任何事情,但LogCat中不会出现错误,java,android,listview,mobile-application,Java,Android,Listview,Mobile Application,在我的列表视图中选择项目时出现问题。当我单击时,什么也没有发生,我无法转到下一个活动,因为当前的列表视图不可单击。 我试着逐行调试代码,但它似乎没有进入mclick的public部分。为什么会变成这样 这是我的密码 import android.app.ProgressDialog; import android.content.Intent; import android.os.AsyncTask; import android.support.v7.app.AppCompatActivity

在我的
列表视图中选择项目时出现问题。当我单击时,什么也没有发生,我无法转到下一个活动,因为当前的
列表视图不可单击。
我试着逐行调试代码,但它似乎没有进入mclick的
public部分。为什么会变成这样

这是我的密码

import android.app.ProgressDialog;
import android.content.Intent;
import android.os.AsyncTask;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ListAdapter;
import android.widget.ListView;
import android.widget.SimpleAdapter;
import android.widget.TextView;
import android.widget.Toast;
import android.widget.Button;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import java.util.ArrayList;
import java.util.HashMap;

public class ViewAllBills extends AppCompatActivity implements ListView.OnItemClickListener {

    private ListView listView;

    private  Button mydebtsBtn;

    private String JSON_STRING;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_view_all_bills);
        listView = (ListView) findViewById(R.id.listView);
        listView.setOnItemClickListener(this);
        getJSON();
        myDebt();
    }


    //for new bill
    public void myDebt() {
        mydebtsBtn = (Button) findViewById(R.id.buttonMyDebt);
        mydebtsBtn.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View arg0) {
                Intent page1 = new Intent(ViewAllBills.this,myDebt.class);
                startActivity(page1);
            }
        });}


    private void showBills(){
        JSONObject jsonObject = null;
        ArrayList<HashMap<String,String>> list = new ArrayList<HashMap<String, String>>();
        try {
            jsonObject = new JSONObject(JSON_STRING);
            JSONArray result = jsonObject.getJSONArray(Config.TAG_JSON_ARRAY);

            for(int i = 0; i<result.length(); i++){
                JSONObject jo = result.getJSONObject(i);
                String id = jo.getString(Config.TAG_ID);
                String desc = jo.getString(Config.TAG_DESCRIPTION);
                String amo = jo.getString(Config.TAG_AMOUNT);

                HashMap<String,String> bills = new HashMap<>();
                bills.put(Config.TAG_ID,id);
                bills.put(Config.TAG_DESCRIPTION,desc);
                bills.put(Config.TAG_AMOUNT,amo);
                list.add(bills);
            }

        } catch (JSONException e) {
            e.printStackTrace();
        }

        ListAdapter adapter = new SimpleAdapter(
                ViewAllBills.this, list, R.layout.list_item,
                new String[]{Config.TAG_ID,Config.TAG_DESCRIPTION,Config.TAG_AMOUNT},
                new int[]{R.id.id, R.id.description,R.id.amountBill});

        listView.setAdapter(adapter);
    }

    private void getJSON(){
        class GetJSON extends AsyncTask<Void,Void,String>{

            ProgressDialog loading;
            @Override
            protected void onPreExecute() {
                super.onPreExecute();
                loading = ProgressDialog.show(ViewAllBills.this,"Fetching Data","Wait...",false,false);
            }

            @Override
            protected void onPostExecute(String s) {
                super.onPostExecute(s);
                loading.dismiss();
                JSON_STRING = s;
                showBills();
            }

            @Override
            protected String doInBackground(Void... params) {
                RequestHandler rh = new RequestHandler();
                String s = rh.sendGetRequest(Config.URL_GET_ALL);
                return s;
            }
        }
        GetJSON gj = new GetJSON();
        gj.execute();

    }

    @Override
    public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
        Intent intent = new Intent(ViewAllBills.this, ViewBills.class);
        HashMap<String,String> map =(HashMap)parent.getItemAtPosition(position);
        String billId = map.get(Config.TAG_ID).toString();
        intent.putExtra(Config.BILL_ID,billId);
        startActivity(intent);
    }

}
导入android.app.ProgressDialog;
导入android.content.Intent;
导入android.os.AsyncTask;
导入android.support.v7.app.AppActivity;
导入android.os.Bundle;
导入android.view.Menu;
导入android.view.MenuItem;
导入android.view.view;
导入android.widget.AdapterView;
导入android.widget.ListAdapter;
导入android.widget.ListView;
导入android.widget.simpledapter;
导入android.widget.TextView;
导入android.widget.Toast;
导入android.widget.Button;
导入org.json.JSONArray;
导入org.json.JSONException;
导入org.json.JSONObject;
导入java.util.ArrayList;
导入java.util.HashMap;
公共类ViewAllBills扩展AppCompativeActivity实现ListView.OnItemClickListener{
私有列表视图列表视图;
专用按钮mydebtsBtn;
私有字符串JSON_字符串;
@凌驾
创建时受保护的void(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.activity\u view\u all\u bills);
listView=(listView)findViewById(R.id.listView);
setOnItemClickListener(this);
getJSON();
我的债务();
}
//新法案
公共债务{
mydebtsBtn=(按钮)findViewById(R.id.buttonMyDebt);
mydebtsBtn.setOnClickListener(新视图.OnClickListener(){
@凌驾
公共void onClick(视图arg0){
Intent page1=新的Intent(ViewAllBills.this,myDebt.class);
星触觉(第1页);
}
});}
私人票据(){
JSONObject JSONObject=null;
ArrayList=新建ArrayList();
试一试{
jsonObject=新的jsonObject(JSON_字符串);
JSONArray result=jsonObject.getJSONArray(Config.TAG\u JSON\u数组);
对于(int i=0;i
这是我的List_item.xml布局

<?xml version="1.0" encoding="utf-8"?>
<ScrollView
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:fillViewport="true"
    android:background="@color/skyBlue"
    >

    <GridLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:columnCount="3"
        android:rowCount="3"
        android:background="@drawable/border_style"
        android:layout_marginTop="5dp">
        <TextView
            android:id="@+id/id"
            android:layout_width="50dp"
            android:layout_height="wrap_content"
            android:textStyle="bold" />

        <TextView
            android:id="@+id/description"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:textStyle="bold"
            />

        <TextView
            android:id="@+id/amountBill"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:textStyle="bold"
            android:layout_gravity="right"
            />
        </GridLayout>
</ScrollView>

试试这个:

import android.app.ProgressDialog;
import android.content.Intent;
import android.os.AsyncTask;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ListAdapter;
import android.widget.ListView;
import android.widget.SimpleAdapter;
import android.widget.TextView;
import android.widget.Toast;
import android.widget.Button;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import java.util.ArrayList;
import java.util.HashMap;

public class ViewAllBills extends AppCompatActivity implements ListView.OnItemClickListener {

    private  Button mydebtsBtn;
    private String JSON_STRING;

    private ListView listView;

    ArrayList<HashMap<String,String>> list;

    ListAdapter adapter;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_view_all_bills);

        listView = (ListView) findViewById(R.id.listView);

        list = new ArrayList<HashMap<String, String>>();

        getJSON();
        myDebt();
    }


    //for new bill
    public void myDebt() {
        mydebtsBtn = (Button) findViewById(R.id.buttonMyDebt);
        mydebtsBtn.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View arg0) {
                Intent page1 = new Intent(ViewAllBills.this,myDebt.class);
                startActivity(page1);
            }
        });}


    private void showBills(){
        JSONObject jsonObject = null;
        try {
            jsonObject = new JSONObject(JSON_STRING);
            JSONArray result = jsonObject.getJSONArray(Config.TAG_JSON_ARRAY);

            for(int i = 0; i<result.length(); i++){
                JSONObject jo = result.getJSONObject(i);
                String id = jo.getString(Config.TAG_ID);
                String desc = jo.getString(Config.TAG_DESCRIPTION);
                String amo = jo.getString(Config.TAG_AMOUNT);

                HashMap<String,String> bills = new HashMap<>();
                bills.put(Config.TAG_ID,id);
                bills.put(Config.TAG_DESCRIPTION,desc);
                bills.put(Config.TAG_AMOUNT,amo);
                list.add(bills);
            }

        } catch (JSONException e) {
            e.printStackTrace();
        }

        adapter = new SimpleAdapter(
                ViewAllBills.this, list, R.layout.list_item,
                new String[]{Config.TAG_ID,Config.TAG_DESCRIPTION,Config.TAG_AMOUNT},
                new int[]{R.id.id, R.id.description,R.id.amountBill});

        listView.setAdapter(adapter);
        listView.setOnItemClickListener(this);
    }

    private void getJSON(){
        class GetJSON extends AsyncTask<Void,Void,String>{

            ProgressDialog loading;
            @Override
            protected void onPreExecute() {
                super.onPreExecute();
                loading = ProgressDialog.show(ViewAllBills.this,"Fetching Data","Wait...",false,false);
            }

            @Override
            protected void onPostExecute(String s) {
                super.onPostExecute(s);
                loading.dismiss();
                JSON_STRING = s;
                showBills();
            }

            @Override
            protected String doInBackground(Void... params) {
                RequestHandler rh = new RequestHandler();
                String s = rh.sendGetRequest(Config.URL_GET_ALL);
                return s;
            }
        }
        GetJSON gj = new GetJSON();
        gj.execute();

    }

    @Override
    public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
        Intent intent = new Intent(ViewAllBills.this, ViewBills.class);
        HashMap<String,String> map = list.get(position);
        String billId = map.get(Config.TAG_ID).toString();
        intent.putExtra(Config.BILL_ID,billId);
        startActivity(intent);
    }

}
导入android.app.ProgressDialog;
导入android.content.Intent;
导入android.os.AsyncTask;
导入android.support.v7.app.AppActivity;
导入android.os.Bundle;
导入android.view.Menu;
导入android.view.MenuItem;
导入android.view.view;
导入android.widget.AdapterView;
导入android.widget.ListAdapter;
导入android.widget.ListView;
导入android.widget.simpledapter;
导入android.widget.TextView;
导入android.widget.Toast;
导入android.widget.Button;
导入org.json.JSONArray;
导入org.json.JSONException;
导入org.json.JSONObject;
导入java.util.ArrayList;
导入java.util.HashMap;
公共类ViewAllBills扩展AppCompativeActivity实现ListView.OnItemClickListener{
专用按钮mydebtsBtn;
私有字符串JSON_字符串;
私有列表视图列表视图;
数组列表;
列表适配器;
@凌驾
创建时受保护的void(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.activity\u view\u all\u bills);
listView=(listView)findViewById(R.id.listView);
列表=新的ArrayList();
getJSON();
我的债务();
}
//新法案
公共债务{
mydebtsBtn=(按钮)findViewById(R.id.buttonMyDebt);
mydebtsBtn.setOnClickListener(新视图.OnClickListener(){
@凌驾
公共void onClick(视图arg0){
Intent page1=新的Intent(ViewAllBills.this,myDebt.class);
星触觉(第1页);
}
});}
私人票据(){
JSONObject JSONObject=null;
试一试{
jsonObject=新的jsonObject(JSON_字符串);
JSONArray result=jsonObject.getJSONArray(Config.TAG\u JSON\u数组);

对于(inti=0;i请尝试以下操作:

import android.app.ProgressDialog;
import android.content.Intent;
import android.os.AsyncTask;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ListAdapter;
import android.widget.ListView;
import android.widget.SimpleAdapter;
import android.widget.TextView;
import android.widget.Toast;
import android.widget.Button;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import java.util.ArrayList;
import java.util.HashMap;

public class ViewAllBills extends AppCompatActivity implements ListView.OnItemClickListener {

    private  Button mydebtsBtn;
    private String JSON_STRING;

    private ListView listView;

    ArrayList<HashMap<String,String>> list;

    ListAdapter adapter;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_view_all_bills);

        listView = (ListView) findViewById(R.id.listView);

        list = new ArrayList<HashMap<String, String>>();

        getJSON();
        myDebt();
    }


    //for new bill
    public void myDebt() {
        mydebtsBtn = (Button) findViewById(R.id.buttonMyDebt);
        mydebtsBtn.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View arg0) {
                Intent page1 = new Intent(ViewAllBills.this,myDebt.class);
                startActivity(page1);
            }
        });}


    private void showBills(){
        JSONObject jsonObject = null;
        try {
            jsonObject = new JSONObject(JSON_STRING);
            JSONArray result = jsonObject.getJSONArray(Config.TAG_JSON_ARRAY);

            for(int i = 0; i<result.length(); i++){
                JSONObject jo = result.getJSONObject(i);
                String id = jo.getString(Config.TAG_ID);
                String desc = jo.getString(Config.TAG_DESCRIPTION);
                String amo = jo.getString(Config.TAG_AMOUNT);

                HashMap<String,String> bills = new HashMap<>();
                bills.put(Config.TAG_ID,id);
                bills.put(Config.TAG_DESCRIPTION,desc);
                bills.put(Config.TAG_AMOUNT,amo);
                list.add(bills);
            }

        } catch (JSONException e) {
            e.printStackTrace();
        }

        adapter = new SimpleAdapter(
                ViewAllBills.this, list, R.layout.list_item,
                new String[]{Config.TAG_ID,Config.TAG_DESCRIPTION,Config.TAG_AMOUNT},
                new int[]{R.id.id, R.id.description,R.id.amountBill});

        listView.setAdapter(adapter);
        listView.setOnItemClickListener(this);
    }

    private void getJSON(){
        class GetJSON extends AsyncTask<Void,Void,String>{

            ProgressDialog loading;
            @Override
            protected void onPreExecute() {
                super.onPreExecute();
                loading = ProgressDialog.show(ViewAllBills.this,"Fetching Data","Wait...",false,false);
            }

            @Override
            protected void onPostExecute(String s) {
                super.onPostExecute(s);
                loading.dismiss();
                JSON_STRING = s;
                showBills();
            }

            @Override
            protected String doInBackground(Void... params) {
                RequestHandler rh = new RequestHandler();
                String s = rh.sendGetRequest(Config.URL_GET_ALL);
                return s;
            }
        }
        GetJSON gj = new GetJSON();
        gj.execute();

    }

    @Override
    public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
        Intent intent = new Intent(ViewAllBills.this, ViewBills.class);
        HashMap<String,String> map = list.get(position);
        String billId = map.get(Config.TAG_ID).toString();
        intent.putExtra(Config.BILL_ID,billId);
        startActivity(intent);
    }

}
导入android.app.ProgressDialog;
导入android.content.Intent;
导入android.os.AsyncTask;
导入android.support.v7.app.AppActivity;
导入android.os.Bundle;
导入android.view.Menu;
导入android.view.MenuItem;
导入android.view.view;
导入android.widget.AdapterView;
导入android.widget.ListAdapter;
导入android.widget.ListView;
导入android.widget.simpledapter;
导入android.widget.TextView;
导入android.widget.Toast;
导入android.widget.Button;
导入org.json.JSONArray;
导入org.json.JSONException;
导入org.json.JSONObject;
导入java.util.ArrayList;
导入java.util.HashMap;
公共类ViewAllBills扩展AppCompativeActivity实现ListView.OnItemClickListener{
专用按钮mydebtsBtn;
私有字符串JSON_字符串;
私有列表视图列表视图;
数组列表;
列表适配器;
@凌驾
创建时受保护的void(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.activity\u view\u all\u bills);
listView=(listView)findViewById(R.id.listView);
列表=新的ArrayList();
getJSON();
我的债务();
}
//新法案
公共债务{
mydebtsBtn=(按钮)findViewById(R.id.buttonMyDebt);
mydebtsBtn.setOnClickListener(新视图.OnClickListener(){
@凌驾
公共void onClick(视图arg0){
Intent page1=新的Intent(ViewAllBills.this,myDebt.class);
星触觉(第1页);
}
});}
私人票据(){
JSONObject JSONObject=null;
试一试{
jsonObject=新的jsonObject(JSON_字符串);
杰索纳雷