<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/LinearLayout1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context=".MainActivity" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal" >
<Button
android:id="@+id/btn3"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="3개" />
<Button
android:id="@+id/btn10"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="10개" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal" >
<Button
android:id="@+id/btnalways"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="always" />
<Button
android:id="@+id/btnnever"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="never" />
<Button
android:id="@+id/btnfscroll"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="ifscroll" />
</LinearLayout>
<ListView
android:id="@+id/list"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</LinearLayout>
package com.example.overscrollex01;
import java.util.ArrayList;
import android.os.Bundle;
import android.app.Activity;
import android.view.Menu;
import android.view.View;
import android.widget.ArrayAdapter;
import android.widget.ListView;
public class MainActivity extends Activity {
ArrayList<String>mItem = new ArrayList<String>();
ArrayAdapter<String> mAdapter;
ListView mList;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
for(int i = 1001 ; i<=1003 ; i++){
mItem.add(Integer.toString(i));
}
mAdapter = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1,mItem);
mList = (ListView)findViewById(R.id.list);
mList.setAdapter(mAdapter);
findViewById(R.id.btn3).setOnClickListener(clickListener);
findViewById(R.id.btn10).setOnClickListener(clickListener);
findViewById(R.id.btnalways).setOnClickListener(clickListener);
findViewById(R.id.btnnever).setOnClickListener(clickListener);
findViewById(R.id.btnfscroll).setOnClickListener(clickListener);
}
private View.OnClickListener clickListener = new View.OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
switch (v.getId()) {
case R.id.btn3:
mItem.clear();
for(int i =1001 ; i<=1003; i++){
mItem.add(Integer.toString(i));
}
mAdapter.notifyDataSetChanged();
break;
case R.id.btn10:
mItem.clear();
for(int i =1001 ; i<=1010; i++){
mItem.add(Integer.toString(i));
}
mAdapter.notifyDataSetChanged();
break;
case R.id.btnalways:
mList.setOverScrollMode(View.OVER_SCROLL_ALWAYS);
break;
case R.id.btnnever:
mList.setOverScrollMode(View.OVER_SCROLL_NEVER);
break;
case R.id.btnfscroll:
mList.setOverScrollMode(View.OVER_SCROLL_IF_CONTENT_SCROLLS);
break;
default:
break;
}
}
};
@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;
}
}
'Android' 카테고리의 다른 글
어댑터뷰 - 그리드 (0) | 2013.04.01 |
---|---|
어댑터 뷰 - 스피너 (0) | 2013.04.01 |
항목 뷰 - ListActivity (0) | 2013.04.01 |
항목 뷰 - 확장리스트뷰 (0) | 2013.04.01 |
항목 뷰 - 커스텀 뷰 (0) | 2013.04.01 |