小编elf*_*foz的帖子

如何根据受保护的String doInBackground方法中的AsyncTask结果调用Toast.makeText()?

我从AsyncTask中的数据库中获取数据,如果它为null,我想要Toast一个警告文本.我在AsyncTask中尝试但是我知道它不是在工作线程中调用的.这是我的doInBackground方法:

protected String doInBackground(Boolean... params) {
        String result = null;
        StringBuilder sb = new StringBuilder();
        try {   
            HttpClient httpclient = new DefaultHttpClient();
            HttpGet httppost = new HttpGet( "http://191.162.2.235/getProducts.php?login=1&user_name="+UserName+"&user_pass="+Password);
            HttpResponse response = httpclient.execute(httppost);
            if (response.getStatusLine().getStatusCode() != 200) {
                Log.d("MyApp", "Server encountered an error");
            }
            BufferedReader reader = new BufferedReader(
                    new InputStreamReader(
                            response.getEntity().getContent(), "UTF8"));  
            sb = new StringBuilder();
            sb.append(reader.readLine() + "\n");
            String line = null;
            while ((line = reader.readLine()) != null) {
                sb.append(line + "\n");
            }
            result = sb.toString();
         if (  result …
Run Code Online (Sandbox Code Playgroud)

java android android-asynctask

2
推荐指数
1
解决办法
3722
查看次数

无法实例化ExpandableListAdapter类型

我尝试在导航抽屉中创建一个ExpandableListView.我尝试了一个示例代码但是在编译之前我遇到了这个错误.

public class MainActivity extends Activity {

     ExpandableListAdapter listAdapter;
    ExpandableListView expListView;
    List<String> listDataHeader;
    HashMap<String, List<String>> listDataChild;

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

        // get the listview
        expListView = (ExpandableListView) findViewById(R.id.left_drawer);

        // preparing list data
        prepareListData();

   listAdapter = new ExpandableListAdapter(this, listDataHeader, listDataChild);
Run Code Online (Sandbox Code Playgroud)

错误在这一行:listAdapter = new ExpandableListAdapter(this,listDataHeader,listDataChild);

为什么它说无法实例化ExpandableListAdapter类型?

java android expandablelistview navigation-drawer

1
推荐指数
1
解决办法
5844
查看次数

WindowManager:MainActivity泄露了原始窗口com.android.internal.policy.impl.PhoneWindow$DecorView@40731aa0

这个警告是什么意思?我开发了一个Android应用程序,我在logcat中看到了这个警告.此警告不会导致关闭应用程序.一切都没有任何问题或中断,但它可能导致我的应用程序中看不到的一些问题?

Continue logcat:    at android.view.ViewRoot.<init>(ViewRoot.java:261)
                        atandroid.view.WindowManagerImpl.addView(WindowManagerImpl.java:170)....
Run Code Online (Sandbox Code Playgroud)

java android

0
推荐指数
1
解决办法
5078
查看次数