80,469
社区成员




<?xml version="1.0" encoding="UTF-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="80dp">
<TextView
android:id="@+id/txtItem"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="12dp"
android:padding="12dp"
android:textSize="18sp"
android:focusable="false"
android:layout_alignParentLeft="true"
android:layout_centerInParent="true"/>
</RelativeLayout>
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<Button
android:id="@+id/btnClear"
android:layout_width="match_parent"
android:layout_height="45dp"
android:layout_alignParentBottom="true"
android:text="@string/clear"
android:visibility="gone" />
<com.handmark.pulltorefresh.library.PullToRefreshListView
android:id="@+id/pull_refresh_list"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_above="@id/btnClear" />
</RelativeLayout>
package com.test.pulllistviewtest;
import java.util.ArrayList;
import java.util.List;
import android.app.ActionBar;
import android.app.Activity;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.Button;
import com.handmark.pulltorefresh.library.PullToRefreshBase.Mode;
import com.handmark.pulltorefresh.library.PullToRefreshListView;
public class PullListView extends Activity{
private PullToRefreshListView listView = null;
private Button btnClear;
private ListAdapter myAdapter;
private List<String> listData;
private boolean flag = false;
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.pulllistview);
listView = (PullToRefreshListView) findViewById(R.id.pull_refresh_list);
btnClear = (Button) findViewById(R.id.btnClear);
ActionBar actionbar = getActionBar();
actionbar.setTitle("PullToRefreshListView");
actionbar.setDisplayShowTitleEnabled(true);
actionbar.setDisplayHomeAsUpEnabled(true);
actionbar.setDisplayShowHomeEnabled(false);
initData();
listView.setAdapter(myAdapter);
listView.setMode(Mode.PULL_FROM_END);
}
private void initData() {
listData = new ArrayList<String>();
for (int i = 0; i < 30; ++i) {
listData.add("测试" + i);
}
myAdapter = new ListAdapter(this, listData);
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.control, menu);
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
if (item.getItemId() == android.R.id.home) {
onBackPressed();
}
if (item.getItemId() == R.id.control) {
if(flag) {
btnClear.setVisibility(View.GONE);
flag = false;
}
else {
btnClear.setVisibility(View.VISIBLE);
flag = true;
}
}
return super.onOptionsItemSelected(item);
}
}