Android开发点滴

本文深入探讨了Android开发中的一些关键技巧,包括设置固定屏幕方向、网络与本地权限管理、多线程执行、ListActivity示例及自定义弹出窗口实现。通过实例代码展示如何在Android应用中高效地进行开发。
摘要由CSDN通过智能技术生成

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


 

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值