android 日常(一)

  • 給LinearLayout添加滾動條
<?xml version="1.0" encoding="utf-8"?> 
<ScrollView      
xmlns:android="[http://schemas.android.com/apk/res/android](http://schemas.android.com/apk/res/android)"  
android:layout_width="fill_parent" 
android:layout_height="fill_parent"
android:scrollbars="vertical"
android:fadingEdge="vertical"
>      
    <LinearLayout
        android:layout_width="fill_parent" 
        android:layout_height="fill_parent"
        android:orientation="vertical" >      
    </LinearLayout> 
</ScrollView> 

<scrollView>下只能有一個子控件

  • Activity之間對象傳遞
    1.所傳的對象 實現(xiàn)接口 Serializable:
    <pre>
    public class Person implements Serializable {
    </pre>
    2.傳遞對象的原始頁面調(diào)用intent.putExtra()即可:
    <pre>
    Intent intent = new Intent();
    Person obj = new Person(wg_name.getText().toString(),wg_age.getText().toString());
    intent.putExtra("Person", obj);
    intent.setClass(Demo_trans_objectActivity.this, OtherActivity.class);
    startActivity(intent);
    </pre>
    3.接收對象的界面使用getIntent().getSerializableExtra()獲取對象:
    <pre>
    Person p = (Person) getIntent().getSerializableExtra("Person");
    ((TextView)findViewById(R.id.name)).setText(p.name);
    ((TextView)findViewById(R.id.age)).setText(p.age);
    </pre>

  • 給Layout設(shè)置邊框
    <pre>
    <?xml version="1.0" encoding="utf-8"?>
    <shape xmlns:android="http://schemas.android.com/apk/res/android" >
    <solid android:color="#FFFFFF" />
    <stroke
    android:width="0.01dp"
    android:color="#FFFFFF" />
    <padding
    android:bottom="1dp"
    android:left="0.5dp"
    android:right="0.5dp"
    android:top="0dp" />
    </shape>
    </pre>
    然后給layout指定background屬性就可以

  • 通過控制臺將sqlite數(shù)據(jù)庫文件導(dǎo)出
    <pre>
    adb pull /data/data/com.yourproject/databases/testdatabase.db d:\shownearby.db
    </pre>

  • EditText添加監(jiān)聽
    監(jiān)聽EditText的變化
    <pre>
    et.addTextChangedListener(new TextWatcher() {
    @Override
    public void beforeTextChanged(CharSequence s, int start, int count,int after) {
    tv.setText("還能輸入"+Rest_Length+"個字");
    }
    @Override
    public void afterTextChanged(Editable s) {
    tv.setText("還能輸入"+Rest_Length+"個字");
    }
    @Override
    public void onTextChanged(CharSequence s, int start, int before, int count) {
    if(Rest_Length>0){
    Rest_Length = MAX_LENGTH - et.getText().length();
    }
    }
    });
    </pre>

  • java中判斷字符串是否為數(shù)字的方法的幾種方法

  • 清空listview(添加了listAdapter)的方法

  1. listView.setAdapter(null);
  2. listAdapter.clear();
    listAdapter.notifyDataSetChanged() ;
最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容