Android开发点滴:
1)固定屏幕纵向<activity android:name=".C6UsersActivity" android:label="@string/app_name" android:screenOrientation="portrait"></activity> landscape为横向
2)网络访问权限<uses-permission android:name="android.permission.INTERNET" />
3)本地读写权限<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"></uses-permission>
4)多线程执行
new Thread(){
public void run(){
Log.d("ApplicationSet","Reflesh UserList begin...");
Log.d("ApplicationSet","Reflesh UserList End...");
}
}.start();
5)ListAcitvity示例
package C6M.Package;
import java.io.File;
import java.util.ArrayList;
import java.util.HashMap;
import C6M.Application.C6MApplication;
import C6M.ConfigOper.ConfigOper;
import C6M.Organization.Dept;
import C6M.Organization.Organization;
import C6M.Organization.User;
import C6M.ServicesOper.SHA1;
import C6M.ServicesOper.ServicesOper;
import android.R.color;
import android.app.Activity;
import android.app.ListActivity;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.Gravity;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.WindowManager.LayoutParams;
import android.widget.Button;
import android.widget.EditText;
import android.widget.LinearLayout;
import android.widget.ListView;
import android.widget.SimpleAdapter;
import android.widget.TextView;
import android.widget.Toast;
public class C6UsersActivity extends ListActivity {
public String serviceurl="******";
public Organization organization=null;
public String userlist="";
public Thread userthread=null;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.users);
Button btnSearch=(Button)findViewById(R.id.btnSearch);
btnSearch.setOnClickListener(btnClickListener);
//getUsers();
}
protected void onListItemClick(ListView l, View v, int position, long id) {
// TODO Auto-generated method stub
super.onListItemClick(l, v, position, id);
try
{
System.out.println("id--------------" + v.getId());
System.out.println("position--------------" + position);
ListView listView = (ListView)l;
HashMap<String, String> map = (HashMap<String, String>) listView.getItemAtPosition(position);
String _userid = map.get("txtUserId");
//String _userid=((TextView)l.getChildAt(position).findViewById(R.id.txtUserId)).getText().toString();
Intent intent = new Intent(C6UsersActivity.this,CallSendActivity.class);
intent.putExtra("UserId",_userid);
startActivity(intent);
}catch(Exception e)
{
Log.d("Application", "Start CallSend Error "+e.getMessage());
}
}
//按钮点击监听操作
public OnClickListener btnClickListener=new OnClickListener()
{
@Override
public void onClick(View v) {
Log.d("ApplicationKey","Begin");
int id=v.getId();
String _Key="" ;
EditText editkey=(EditText)findViewById(R.id.txtKey);
_Key=editkey.getText().toString();
Log.d("ApplicationKey",_Key);
switch(id)
{
case R.id.btnSearch:
CreatUserList(_Key);
break;
}
}
};
//获取用户列表
public Organization GetOrganization()
{
Organization _ret=new Organization();
String _classarray=",DeptList,ChildUsers,";
_ret=(Organization)ServicesOper.GetObjectInfo(new File("sdcard/C6M/UserList.dat"),"C6M.Organization",_classarray);
return _ret;
}
//创建用户列表
public void CreatUserList(String _Key)
{
if(C6MApplication.organization==null)
{
return;
}
int count=0;
//_Key=_Key+"李";
Organization _org=C6MApplication.organization;
ArrayList<HashMap<String, String>> list = new ArrayList<HashMap<String,String>>();
for(int i=0;i<_org.DeptList.size();i++)
{
Dept _dept=(Dept)_org.DeptList.get(i);
for(int j=0;j<_dept.ChildUsers.size();j++)
{
//Log.d("CreatTree", "UserBegin "+String.valueOf(_Key.length()));
User _user=(User)_dept.ChildUsers.get(j);
//if(_Key.length()>0)
if(_Key!=null &&!_Key.equals("")&&_user.UserName.lastIndexOf(_Key)<0)
continue;
HashMap<String, String> map1 = new HashMap<String, String>();
map1.put("txtUserName", _user.UserName);
map1.put("txtUserId", _user.UserId);
list.add(map1);
count++;
Log.d("CreatTree", "UserEnd");
// if(count>20) break;
}
//if(count>20) break;
}
Log.d("Application",String.valueOf(list.size()));
//生成一个SimpleAdapter类型的变量来填充数据
SimpleAdapter listAdapter = new SimpleAdapter(this, list, R.layout.user, new String[]{"txtUserName" , "txtUserId"}, new int[]{R.id.txtUserName , R.id.txtUserId});
setListAdapter(listAdapter);
}
}
自定义弹出窗口实现
@Override
public boolean onPrepareOptionsMenu(Menu menu)
{
showTopWindow();
return true;
}
public void showTopWindow(){
if(Setalert==null)
{
LayoutInflater flater = LayoutInflater.from(this);
view = flater.inflate(R.layout.menu, null);
Log.d("T","show beg");
AlertDialog.Builder builder = new AlertDialog.Builder(C6UnReadMsg.this);
builder.setView(view);
Setalert = builder.create();
Setalert.show();
//((TextView)(view.findViewById(R.id.txtAddress))).setText(C6MApplication.ServiceUrl);
ImageButton btnSet=(ImageButton)view.findViewById(R.id.btnUserList);
btnSet.setOnClickListener(btnClickListener);
Log.d("T","show end");
}else
{
Setalert.show();
}
}