widget 상용 UI 컨트롤 소개

25046 단어 widget

 
단일 선택 상자

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"

    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="vertical"
    tools:context=".MainActivity" >
 
    <!-- checkedButton      woman   ,         id woman    -->
  <RadioGroup 
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="vertical"
    android:checkedButton="@+id/woman"
    android:id="@+id/sex"
      >
      
      <RadioButton
          android:text="@string/man"
          android:id="@+id/man"
          ></RadioButton>
    <RadioButton
        android:text="@string/woman"
        android:id="@id/woman"
         />
      </RadioGroup>
 
</LinearLayout>


.csharpcode, .csharpcode pre
{
font-size: small;
color: black;
font-family: consolas, "Courier New", courier, monospace;
background-color: #ffffff;
/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt
{
background-color: #f4f4f4;
width: 100%;
margin: 0em;
}
.csharpcode .lnum { color: #606060; }
widget 常用UI控件介绍_第1张图片
widget 常用UI控件介绍_第2张图片
 
2.체크 상자
widget 常用UI控件介绍_第3张图片
 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="vertical"
    tools:context=".MainActivity" >
 
    <!-- checkedButton      woman   ,         id woman    -->
    <TextView
     android:layout_width="fill_parent"
     android:layout_height="wrap_content"
     android:text="@string/favoriteString"
     android:id="@+id/favorite"/>
  <RelativeLayout 
      android:layout_width="fill_parent"
      android:layout_height="fill_parent"
      >
      
      <CheckBox 
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="@string/pingpong"
        android:id="@+id/my"
        ></CheckBox>
        <CheckBox 
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="@string/pingpong"
        android:layout_toRightOf="@id/my"
        android:id="@+id/my2"
        ></CheckBox>
           
  </RelativeLayout>  
    
 
</LinearLayout>


.csharpcode, .csharpcode pre
{
font-size: small;
color: black;
font-family: consolas, "Courier New", courier, monospace;
background-color: #ffffff;
/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt
{
background-color: #f4f4f4;
width: 100%;
margin: 0em;
}
.csharpcode .lnum { color: #606060; }
3.ListView
다음은 ListView 류 의 상용 방법 을 배 워 보 겠 습 니 다."setAdapter(ListAdapter adapter)는 ListView 로 Adapter"setChoiceMode(int choiceMode)를 ListView 로 표시 할 모드 를 지정 합 니 다.선택 가능 한 값 은 세 개의 CHOICE 입 니 다.MODE_NONE(기본 값,단일 선택 또는 다 중 선택 효과 없 음),CHOICEMODE_SINGLE(체크 상자 효과),CHOICEMODE_MULTIPLE(다 중 선택 상자 효과);"setOnItemClickListener(AdapterView.OnItemClickListener listener)는 클릭 된 이벤트 의 모니터 를 등록 합 니 다.그 중 하 나 를 클릭 했 을 때 매개 변수 listener 의 onItemClick()방법 을 호출 합 니 다.
package com.buu.listview;
import android.os.Bundle;
import android.app.Activity;
import android.view.Menu;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.ListAdapter;
import android.widget.ListView;
import android.widget.Toast;
 
public class MainActivity extends Activity {
    private  String[]  options;
    ListView lView;
 
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);  //        ,  listview      。
        options = getResources().getStringArray(R.array.options);
        
        lView =(ListView) findViewById(R.id.listView1);
//      ListAdapter adapter = new  ArrayAdapter<String>(MainActivity.this, R.layout.main_lv_text, options);
        ListAdapter adapter = new ArrayAdapter<String>(MainActivity.this, android.R.layout.simple_list_item_1, options);
      lView.setAdapter(adapter);
      lView.setOnItemClickListener(new OnItemClickListener() {
          @Override
        public void onItemClick(AdapterView<?> parent, View view, int position,
                long id) {
            // TODO Auto-generated method stub
              String option = options[position];
            Toast.makeText(MainActivity.this, "     :"+option, 2000).show(); 
        }
    });
    }
 
    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        // Inflate the menu; this adds items to the action bar if it is present.
        getMenuInflater().inflate(R.menu.main, menu);
        return true;
    }
 
}


.csharpcode, .csharpcode pre
{
font-size: small;
color: black;
font-family: consolas, "Courier New", courier, monospace;
background-color: #ffffff;
/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt
{
background-color: #f4f4f4;
width: 100%;
margin: 0em;
}
.csharpcode .lnum { color: #606060; }
아래 의 방식 을 비교 하 세 요:
listView = (ListView) findViewById(R.id.listview);
//    ArrayAdapter
ArrayAdapter adapter =
new ArrayAdapter(this, android.R.layout.simple_list_item_1,name);
listView.setAdapter(adapter);
//listView             
listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
//              
public void onItemClick(AdapterView<?> arg0, View arg1, int arg2,long
arg3) {
Toast.makeText(ListViewActivity.this,name[arg2] ,
Toast.LENGTH_LONG).show();
}


.csharpcode, .csharpcode pre
{
font-size: small;
color: black;
font-family: consolas, "Courier New", courier, monospace;
background-color: #ffffff;
/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt
{
background-color: #f4f4f4;
width: 100%;
margin: 0em;
}
.csharpcode .lnum { color: #606060; }
 
설명:ArrayAdapter adapter=new ArrayAdapter(Context context,int textView ResourceId,Object[]objects);Array Adapter 구조 방법의 매개 변수 설명:context:현재 Context 대상 textView ResourceId:TextView 요 소 를 포함 하 는 레이아웃 파일 로 ListView 의 모든 디 스 플레이 형식 을 지정 합 니 다.앞에서 소개 한 바 와 같이 android.R.layot.simplelist_item_1.Android 플랫폼 에서 자체 적 으로 가 져 온 레이아웃 파일 로 TextView 태그 만 포함 되 어 있 습 니 다.그 내용 은 다음 과 같다. http://schemas.android.com/apk/res/android" android:id="@android:id/text1" android:layout_width="fill_parent" android:layout_height="wrap_content" android:textAppearance="?android:attr/textAppearanceLarge" android:gravity="center_vertical" android:paddingLeft="6dip" android:minHeight="?android:attr/list PreferredItemHeight"/>objects:표시 할 데 이 터 는 하나의 배열 인 onItemClick(AdapterViewparent, View view, int position, long id)
인자 소개:parent:클릭 된 ListView 대상 view:클릭 된 position:클릭 된 ListView 의 위치 id:선 택 된 줄 의 id
4.드 롭 다운 목록 상자(Spinner)
휴대 전화의 화면 이 작 기 때문에 드 롭 다운 목록 을 사용 하여 선택 식 입력 을 하 는 것 이 좋 은 방법 이다.Spinner 는 ListView 와 마찬가지 로 AdapterView 의 간접 하위 클래스 로 데 이 터 를 표시 하 는 창 입 니 다.Spinner 류 에서 자주 사용 하 는 방법 은 다음 과 같 습 니 다."Spinner.getItemAtPosition(Spinner.getSelected ItemPosition();드 롭 다운 목록 상자 의 값 을 가 져 옵 니 다.
 
 
arrays.xml 파일 작성
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string-array name="colors">
<item>red</item>
<item>orange</item>
<item>yellow</item>
<item>green</item>
<item>blue</item>
<item>violet</item>
</string-array>


.csharpcode, .csharpcode pre
{
font-size: small;
color: black;
font-family: consolas, "Courier New", courier, monospace;
background-color: #ffffff;
/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt
{
background-color: #f4f4f4;
width: 100%;
margin: 0em;
}
.csharpcode .lnum { color: #606060; }
main.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" >
    <TextView
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:text="@string/colors"
        ></TextView>
    
    <Spinner
        android:id="@+id/spinner"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:prompt="@string/red"
        android:entries="@array/colors"
        >
    </Spinner>
</LinearLayout>


.csharpcode, .csharpcode pre
{
font-size: small;
color: black;
font-family: consolas, "Courier New", courier, monospace;
background-color: #ffffff;
/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt
{
background-color: #f4f4f4;
width: 100%;
margin: 0em;
}
.csharpcode .lnum { color: #606060; }
widget 常用UI控件介绍_第4张图片
그 중:
설명:android:prompt="@string/color팝 업 드 롭 다운 목록 의 제목 을 설정 합 니 다.android:entries="@array/colors"드 롭 다운 목록 의 데 이 터 를 지정 합 니 다.이 예 는 arrays.xm 파일 에서 정의 하 는 colors 배열 입 니 다.

좋은 웹페이지 즐겨찾기