編輯:關於Android編程
MainActivity.java
[java]
package com.example.test;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import android.os.Bundle;
import android.app.Activity;
import android.app.AlertDialog;
import android.app.Dialog;
import android.content.DialogInterface;
import android.view.Menu;
import android.view.View;
import android.view.WindowManager;
import android.widget.Button;
import android.widget.ListView;
public class MainActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Button btn=(Button)findViewById(R.id.button1);
btn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
List<Map<String, Object>> lst_data = new ArrayList<Map<String, Object>>();
for(int i=0;i<20;i++){
Map<String, Object> map = new HashMap<String, Object>();
map.put("Name", "內容"+i);
lst_data.add(map);
}
ListView lst_category = new ListView(MainActivity.this);
DeleteCategoryAdapter adapter = new DeleteCategoryAdapter(
MainActivity.this, lst_data);
lst_category.setAdapter(adapter);
AlertDialog alertDialog = new AlertDialog.Builder(
MainActivity.this).create();
alertDialog.setTitle("修改");
alertDialog.setIcon(android.R.drawable.ic_dialog_info);
alertDialog.setView(lst_category);
alertDialog.setButton(Dialog.BUTTON_POSITIVE, "正確",
new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog,
int which) {
// TODO Auto-generated method stub
}
});
alertDialog.setButton(Dialog.BUTTON_NEGATIVE, "取消",
new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog,
int which) {
// TODO Auto-generated method stub
}
});
alertDialog.show();
alertDialog.getWindow().clearFlags(
WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM);
}
});
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.activity_main, menu);
return true;
}
}
package com.example.test;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import android.os.Bundle;
import android.app.Activity;
import android.app.AlertDialog;
import android.app.Dialog;
import android.content.DialogInterface;
import android.view.Menu;
import android.view.View;
import android.view.WindowManager;
import android.widget.Button;
import android.widget.ListView;
public class MainActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Button btn=(Button)findViewById(R.id.button1);
btn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
List<Map<String, Object>> lst_data = new ArrayList<Map<String, Object>>();
for(int i=0;i<20;i++){
Map<String, Object> map = new HashMap<String, Object>();
map.put("Name", "內容"+i);
lst_data.add(map);
}
ListView lst_category = new ListView(MainActivity.this);
DeleteCategoryAdapter adapter = new DeleteCategoryAdapter(
MainActivity.this, lst_data);
lst_category.setAdapter(adapter);
AlertDialog alertDialog = new AlertDialog.Builder(
MainActivity.this).create();
alertDialog.setTitle("修改");
alertDialog.setIcon(android.R.drawable.ic_dialog_info);
alertDialog.setView(lst_category);
alertDialog.setButton(Dialog.BUTTON_POSITIVE, "正確",
new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog,
int which) {
// TODO Auto-generated method stub
}
});
alertDialog.setButton(Dialog.BUTTON_NEGATIVE, "取消",
new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog,
int which) {
// TODO Auto-generated method stub
}
});
alertDialog.show();
alertDialog.getWindow().clearFlags(
WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM);
}
});
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.activity_main, menu);
return true;
}
}
DeleteCategoryAdapter.java
[java]
package com.example.test;
import java.util.List;
import java.util.Map;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.CheckBox;
import android.widget.EditText;
import android.widget.TextView;
public class DeleteCategoryAdapter extends BaseAdapter {
private Context context;
private List<Map<String, Object>> listItems;
private LayoutInflater listContainer;
public DeleteCategoryAdapter(Context context,
List<Map<String, Object>> listItems) {
this.context = context;
// create view and settings context
listContainer = LayoutInflater.from(context);
this.listItems = listItems;
}
// Custom widget
public final class ListItemView {
public TextView txtV_category;
public CheckBox ckb_category;
}
@Override
public int getCount() {
// TODO Auto-generated method stub
return listItems.size();
}
@Override
public Object getItem(int position) {
// TODO Auto-generated method stub
if (position < listItems.size()) {
return listItems.get(position);
}
return null;
}
@Override
public long getItemId(int position) {
// TODO Auto-generated method stub
return position;
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
// TODO Auto-generated method stub
ListItemView listItemView = new ListItemView();
if (convertView == null) {
convertView = listContainer.inflate(R.layout.show_deletecategory,
null);
listItemView.txtV_category = (TextView) convertView
.findViewById(R.id.deletecategory_txtV_category);
listItemView.ckb_category = (CheckBox) convertView
.findViewById(R.id.deletecategory_ckb_select);
convertView.setTag(listItemView);
} else {
listItemView = (ListItemView) convertView.getTag();
}
listItemView.txtV_category.setText((String) listItems.get(position)
.get("Name"));
listItemView.ckb_category.setTag((String) listItems.get(position).get(
"ID"));
return convertView;
}
}
本文主要記錄了Launcher3拖動時的流程和代碼記錄,在桌面圖標拖動時會引起圖標的重排,拖動時受影響的圖標在文中由item或cell來表示。 圖標點擊效果和搖動效
經過前面兩篇文章的學習,我想大家對ActionBar都已經有一個相對較為深刻的理解了。唯一欠缺的是,前面我們都只是學習了理論知識而已,雖然知識點已經掌握了,
android的輸入管理系統主要完成按鍵、觸摸板、鼠標等輸入設備的事件輸入,功能包括,輸入設備的事件輸入及向焦點窗口和焦
本文實例講述了Android開發之自定義控件用法。分享給大家供大家參考,具體如下:今天和大家分享下組合控件的使用。很多時候android自定義控件並不能滿足需求,如何做呢