最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

Android開(kāi)發(fā)常見(jiàn)錯(cuò)誤小結(jié)

 更新時(shí)間:2015年05月27日 11:59:35   作者:imzoer  
這篇文章主要介紹了Android開(kāi)發(fā)常見(jiàn)錯(cuò)誤,實(shí)例分析了常見(jiàn)的Android開(kāi)發(fā)中遇到的錯(cuò)誤,對(duì)Android開(kāi)發(fā)有一定參考借鑒價(jià)值,需要的朋友可以參考下

本文實(shí)例總結(jié)了Android開(kāi)發(fā)的常見(jiàn)錯(cuò)誤。分享給大家供大家參考。具體如下:

錯(cuò)誤1:

在intent中添加了一個(gè)內(nèi)容,在調(diào)用getStringExtra讀取的時(shí)候,總是報(bào)錯(cuò)。代碼如下:

// back按鈕 
Button btnBack = (Button) findViewById(R.id.btnActivity2Back);
btnBack.setOnClickListener(new OnClickListener() { 
  @Override 
  public void onClick(View v) { 
 Intent intent = new Intent(); 
 intent.putExtra("from", 2); 
 setResult(RESULT_OK, intent); 
 finish(); 
  } 
});

其中調(diào)用了intent的putExtra方法。

讀取代碼如下:

@Override 
protected void onActivityResult(int requestCode, int resultCode, Intent data) { 
    TextView tview = (TextView) findViewById(R.id.textViewResult1);
    if (data != null) { 
      tview.setText("從" + data.getStringExtra("from") + "返回!");
    } 
    super.onActivityResult(requestCode, resultCode, data); 
}

調(diào)用了getStringExtra來(lái)讀取數(shù)據(jù)。這里會(huì)報(bào)錯(cuò)。

錯(cuò)誤原因:

在putExtra的時(shí)候,代碼intent.putExtra("from", 2);中,2并不是一個(gè)字符串,而是一個(gè)數(shù)字。因此,在讀取的時(shí)候,調(diào)用getStringExtra報(bào)錯(cuò)了。

如果這么寫(xiě):intent.putExtra("from", 2 + "");就不會(huì)有問(wèn)題。

錯(cuò)誤2:

在做listview使用simplecursoradapter的時(shí)候,遇到下面的這個(gè)問(wèn)題。

java.lang.UnsupportedOperationException: addView(View, LayoutParams) is not supported in AdapterView

這個(gè)錯(cuò)誤原因是我在main.xml布局文件中,將TextView控件包含在了<ListView>控件內(nèi)部而出現(xiàn)的錯(cuò)誤,在設(shè)計(jì)中用來(lái)顯示數(shù)據(jù)的控件,最好放在另外一個(gè)布局文件中。

比如說(shuō),我的listview的xml為:

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
  android:layout_width="fill_parent" 
  android:layout_height="fill_parent" 
  android:orientation="vertical" > 
  <Button 
    android:id="@+id/btnInitData5000" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:text="初始化數(shù)據(jù)5000條" /> 
  <Button 
    android:id="@+id/btnInitListView" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:text="讀取數(shù)據(jù)初始化ListView" /> 
  <ListView 
    android:id="@+id/listView4" 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" > 
  </ListView> 
</LinearLayout>

listview的xml中只寫(xiě)listview的xml,而把每行要顯示的內(nèi)容,放在了myrow.xml中,如下:

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
  android:layout_width="match_parent" 
  android:layout_height="wrap_content" > 
  <TextView 
    android:id="@+id/textViewItemName" 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" /> 
</LinearLayout> 

錯(cuò)誤3:

從listview的一個(gè)item點(diǎn)擊,跳轉(zhuǎn)到另外一個(gè)activity的時(shí)候,動(dòng)畫(huà)效果是不對(duì)的。

startActivity(intent); 
// finish(); 
  Log.e("mason", "gongneng ani called"); 
  overridePendingTransition(R.anim.slide_out_right, 
   R.anim.slide_in_left);

如上面的代碼。但是如果先調(diào)用finish()函數(shù),動(dòng)畫(huà)效果就對(duì)了。但是此時(shí)有個(gè)問(wèn)題。進(jìn)入了新的activity之后,按back鍵,不能回到原來(lái)的activity了。這是因?yàn)樵瓉?lái)的activity調(diào)用了finish函數(shù),finish函數(shù)相當(dāng)于用戶按下了back鍵。相當(dāng)于告訴了安卓系統(tǒng),這個(gè)activity可以被回收了(此時(shí)在安卓activity棧中這個(gè)activity也不存在了)。

希望本文所述對(duì)大家的Android程序設(shè)計(jì)有所幫助。

相關(guān)文章

最新評(píng)論

长子县| 收藏| 棋牌| 巴彦淖尔市| 桑植县| 定远县| 柳林县| 尼木县| 湘乡市| 红河县| 丹江口市| 阿图什市| 梁山县| 信阳市| 府谷县| 赤峰市| 平阴县| 鹤庆县| 类乌齐县| 大城县| 辽宁省| 乐昌市| 漯河市| 苏尼特右旗| 略阳县| 清丰县| 健康| 修水县| 岱山县| 宜君县| 铁力市| 大兴区| 兴义市| 镶黄旗| 昌宁县| 怀柔区| 松江区| 沭阳县| 虹口区| 铁力市| 郴州市|