Android Restful API改造在创建方法上获取数据,但不显示



这是完整的代码(在第一个活动中,两个值是从旋转器和发送到第二个活动的函数数据中获取的(

第一个活动:

public class FindBloodActivity extends AppCompatActivity {
    String API = "http://abdolqadir-001-site1.ctempurl.com/Account.svc";
    TextView t;
    Spinner spbgid;
    Spinner spcityid;
    ProgressBar pro;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_find_blood);
        t = (TextView) findViewById(R.id.tv);
        pro=(ProgressBar) findViewById(R.id.progressBar2);
        pro.setVisibility(View.INVISIBLE);
        spbgid=(Spinner) findViewById(R.id.spinnerBG);
        spcityid=(Spinner) findViewById(R.id.spinnerLocation);
        t.setVisibility(View.INVISIBLE);
    }
    public void SearchOn(View v)  {
        String BGId = Integer.toString(spbgid.getSelectedItemPosition()+1);
        String CityId =Integer.toString(spcityid.getSelectedItemPosition()+1);
        Intent intent=new Intent(getApplicationContext(),SearchResult2.class);
        intent.putExtra("bid",BGId);
        intent.putExtra("cid",CityId);
        startActivity(intent);
    }
}

第二个活动:在tt.append上的第二个活动中(string.tostring(((;工作正常,但是当我添加以下代码以下时,如果我尝试调试,则终止应用程序终止。

public class SearchResult2 extends AppCompatActivity {
    String API = "http://abdolqadir-001-site1.ctempurl.com/Account.svc";
    Spinner sp;
    TextView t;
    TextView tt;
    public int totalUsersCount = 0;
    String[] allUserNames;
    String[] allUserContacts;
    ListView listView;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_search_result2);
        tt=(TextView)findViewById(R.id.tvTest);
        tt.setVisibility(View.INVISIBLE);
        Bundle extras = getIntent().getExtras();
        String BGId = extras.getString("bid");
        String CityId = extras.getString("cid");
        tt.setText("");
        final RestAdapter restAdapter = new RestAdapter.Builder()
                .setEndpoint(API).build();
        final gitapi git = restAdapter.create(gitapi.class);
        git.SearchUsers(BGId, CityId, new Callback<String>() {
            @Override
            public void success(String string, Response response) {
                    tt.append(string.toString());
            }
            @Override
            public void failure(RetrofitError retrofitError) {
                tt.setText("No User Found");
            }
        });
            String bigArray = tt.getText().toString();
            listView = (ListView)findViewById(R.id.lvUsers);
            bigArray = bigArray.substring(0, bigArray.length() - 1);
            totalUsersCount = bigArray.split(",").length;
            listView.clearTextFilter();
            if (totalUsersCount > 0)
            {
                String[] allUsers = new String[totalUsersCount];
                allUsers = bigArray.split(",");
                allUserNames = new String[totalUsersCount];
                allUserContacts = new String[totalUsersCount];
                String[] temp = new String[3];
                for (int i = 0; i < totalUsersCount; i++) {
                    temp = allUsers[i].split("-");
                    allUserNames[i] = temp[1];
                    allUserContacts[i] = temp[2];
                }
                ArrayAdapter<String> itemsAdapter =
                        new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, allUserNames);
                listView.setAdapter(itemsAdapter);
                listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
                    @Override
                    public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
                        SendSMS(position);
                    }
                });
            }
    }
}

这是log

02-08 12:40:51.433 9970-10008/com.example.abdulqadir.bd I/OpenGLRenderer: Initialized EGL, version 1.4
02-08 12:40:51.457 9970-10008/com.example.abdulqadir.bd W/linker: /vendor/lib64/libhwuibp.so: unused DT entry: type 0xf arg 0xe3a
02-08 12:40:51.458 9970-9970/com.example.abdulqadir.bd W/art: Before Android 4.1, method int android.support.v7.widget.ListViewCompat.lookForSelectablePosition(int, boolean) would have incorrectly overridden the package-private method in android.widget.ListView
02-08 12:40:51.548 9970-10008/com.example.abdulqadir.bd E/hwaps: APS: SSR : The platform cannot support SSR !: 0x0,0x0,8

下面的此代码对我来说很好,但是当我将其更改为上述比出现错误时,这里是代码,请检查

public class FindBloodActivity extends AppCompatActivity {
    String API = "http://abdolqadir-001-site1.ctempurl.com/Account.svc";
    TextView t;
    Spinner spbgid;
    Spinner spcityid;
    ProgressBar pro;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_find_blood);
        t = (TextView) findViewById(R.id.tv);
        pro=(ProgressBar) findViewById(R.id.progressBar2);
        pro.setVisibility(View.INVISIBLE);
        spbgid=(Spinner) findViewById(R.id.spinnerBG);
        spcityid=(Spinner) findViewById(R.id.spinnerLocation);
        t.setVisibility(View.INVISIBLE);
    }
    public void SearchOn(View v)  {
        String BGId = Integer.toString(spbgid.getSelectedItemPosition()+1);
        String CityId =Integer.toString(spcityid.getSelectedItemPosition()+1);
        SearchAllUsers(BGId.toString(), CityId.toString());
    }
    public void SearchAllUsers(String BGId,String CityId) {
        t.setText("");
        final RestAdapter restAdapter = new RestAdapter.Builder()
                .setEndpoint(API).build();
        final gitapi git= restAdapter.create(gitapi.class);
        git.SearchUsers(BGId,CityId,new Callback<String>() {
            @Override
            public void success(String string, Response response) {
                t.append(string.toString());
            }
            @Override
            public void failure(RetrofitError retrofitError) {
                t.setText("No User Found");
            }
        });
    }
    public void Search(View v){
        try {
            Thread.sleep(9000);
            Intent intent=new Intent(getApplicationContext(),SearchResult.class);
            intent.putExtra("users",t.getText().toString());
            startActivity(intent);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
    }
}

第二个活动:

public class SearchResult2 extends AppCompatActivity {
    String API = "http://abdolqadir-001-site1.ctempurl.com/Account.svc";
    Spinner sp;
    TextView t;
    TextView tt;
    public int totalUsersCount = 0;
    String[] allUserNames;
    String[] allUserContacts;
    ListView listView;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_search_result2);
        tt=(TextView)findViewById(R.id.tvTest);
        tt.setVisibility(View.INVISIBLE);
        Bundle extras = getIntent().getExtras();
        String BGId = extras.getString("bid");
        String CityId = extras.getString("cid");
        tt.setText("");
        final RestAdapter restAdapter = new RestAdapter.Builder()
                .setEndpoint(API).build();
        final gitapi git = restAdapter.create(gitapi.class);
        git.SearchUsers(BGId, CityId, new Callback<String>() {
            @Override
            public void success(String string, Response response) {
                    tt.append(string.toString());
            }
            @Override
            public void failure(RetrofitError retrofitError) {
                tt.setText("No User Found");
            }
        });
            String bigArray = tt.getText().toString();
            listView = (ListView)findViewById(R.id.lvUsers);
            bigArray = bigArray.substring(0, bigArray.length() - 1);
            totalUsersCount = bigArray.split(",").length;
            listView.clearTextFilter();
            if (totalUsersCount > 0)
            {
                String[] allUsers = new String[totalUsersCount];
                allUsers = bigArray.split(",");
                allUserNames = new String[totalUsersCount];
                allUserContacts = new String[totalUsersCount];
                String[] temp = new String[3];
                for (int i = 0; i < totalUsersCount; i++) {
                    temp = allUsers[i].split("-");
                    allUserNames[i] = temp[1];
                    allUserContacts[i] = temp[2];
                }
                ArrayAdapter<String> itemsAdapter =
                        new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, allUserNames);
                listView.setAdapter(itemsAdapter);
                listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
                    @Override
                    public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
                        SendSMS(position);
                    }
                });
            }
    }

这是您可以尝试的事情,在onCreate()

中使用此代码
 listView = (ListView)findViewById(R.id.lvUsers);
ArrayAdapter<String> itemsAdapter =
                    new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, allUserNames);
            listView.setAdapter(itemsAdapter);
            listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
                @Override
                public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
                    SendSMS(position);
                }
            });

以及您在位置使用上述代码,然后再将其内部替换为IF条件

itemsAdapter.notifyDatasetChanged();

希望这有帮助

为什么不从ongreate((方法中进行休息呼叫? 还有组件。设置可视频(View.Indible(;保留整体布局中的空间。您可以使用"消失",看看是否有帮助或受伤。 并尝试使用不同的方法或类中的URL和其他组件。这可以帮助大大保持代码清洁和易于查找错误。

所有这么说,在使用断点并在调试模式下运行哪个行之后?

相关内容

  • 没有找到相关文章