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; }


2.체크 상자

<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 태그 만 포함 되 어 있 습 니 다.그 내용 은 다음 과 같다.
인자 소개: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; }

그 중:
설명:android:prompt="@string/color팝 업 드 롭 다운 목록 의 제목 을 설정 합 니 다.android:entries="@array/colors"드 롭 다운 목록 의 데 이 터 를 지정 합 니 다.이 예 는 arrays.xm 파일 에서 정의 하 는 colors 배열 입 니 다.
이 내용에 흥미가 있습니까?
현재 기사가 여러분의 문제를 해결하지 못하는 경우 AI 엔진은 머신러닝 분석(스마트 모델이 방금 만들어져 부정확한 경우가 있을 수 있음)을 통해 가장 유사한 기사를 추천합니다:
【Flutter】 뒤로 버튼으로 전환 소스 화면에 값을 전달하는 방법Flutter 스마트폰 앱에 표준으로 제공되는 왼쪽 상단의 뒤로 버튼. 이번에는, 그 「뒤로 버튼을 눌렀을 때에 값을 건네주는 방법」에 대해 설명합니다. 【전이처 화면】 onWillPop에 값을 건네주는 처리를 추가...
텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
CC BY-SA 2.5, CC BY-SA 3.0 및 CC BY-SA 4.0에 따라 라이센스가 부여됩니다.