美文网首页
android 日常(一)

android 日常(一)

作者: ncd | 来源:发表于2016-07-25 18:41 被阅读10次
    • 给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.所传的对象 实现接口 Serializable:
      <pre>
      public class Person implements Serializable {
      </pre>
      2.传递对象的原始页面调用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设置边框
      <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数据库文件导出
      <pre>
      adb pull /data/data/com.yourproject/databases/testdatabase.db d:\shownearby.db
      </pre>

    • EditText添加监听
      监听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中判断字符串是否为数字的方法的几种方法

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

    1. listView.setAdapter(null);
    2. listAdapter.clear();
      listAdapter.notifyDataSetChanged() ;

    相关文章

      网友评论

          本文标题:android 日常(一)

          本文链接:https://www.haomeiwen.com/subject/mkggjttx.html