android - 我的edittext没有显示callLog数字,当 presssed eventhough可以进入callLog时

  显示原文与译文双语对照的内容
0 0

经过一些研究和编码之后,我就可以进入我的callLog 。 在我添加了更多代码以便能够从callLog检索数字到edittext之后,似乎有错误。 我已经在这个网站上搜索到了。 有什么建议-Simon -?


import java.sql.Date;
import java.util.ArrayList;
import java.util.List;

import android.app.Activity;
import android.app.AlertDialog;
import android.content.DialogInterface;
import android.content.Intent;
import android.database.Cursor;
import android.net.Uri;
import android.os.Bundle;
import android.provider.CallLog;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;

public class SimonCallLogActivity extends Activity {
/** Called when the activity is first created. */
EditText display;
Button log;

@Override
public void onCreate(Bundle savedInstanceState) {
 super.onCreate(savedInstanceState);
 setContentView(R.layout.main);

//to go to Call Log//
 log=(Button)findViewById(R.id.button1); 
 log.setOnClickListener(new Button.OnClickListener(){

 public void onClick(View v) { 
 Intent myIntent=new Intent();
 myIntent.setAction(Intent.ACTION_CALL_BUTTON);
 startActivity(myIntent);
 }
 });
}
//Call Log//
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
 super.onActivityResult(requestCode, resultCode, data);
 final EditText number = (EditText) findViewById(R.id.editText1);
 Cursor cursor = null;
 String phoneNo ="";
 List<String> logNumbers = new ArrayList<String>();

 String[] projection = new String[] {CallLog.Calls.NUMBER, CallLog.Calls.DATE, CallLog.Calls.CACHED_NAME};
 Uri contacts = CallLog.Calls.CONTENT_URI;

 Cursor managedCursor = managedQuery(contacts, projection, null, null, CallLog.Calls.DATE +" ASC");
 getColumnData(managedCursor);
 }
private void getColumnData(Cursor cur){
 try{
 if (cur.moveToFirst()) {
 String name;
 String number;
 long date;
 int nameColumn = cur.getColumnIndex(CallLog.Calls.CACHED_NAME);
 int numberColumn = cur.getColumnIndex(CallLog.Calls.NUMBER);
 int dateColumn = cur.getColumnIndex(CallLog.Calls.DATE);

 System.out.println("Reading Call Details:");
 do {
 name = cur.getString(nameColumn);
 number = cur.getString(numberColumn);
 date = cur.getLong(dateColumn);
 System.out.println(number +":"+ new Date(date) +":"+name);
//number.setText(numberColumn);

 } while (cur.moveToNext());
 }
 } 
 finally
 {
 cur.close();
 }

 final String [] items = logNumbers.toArray(new String[logNumbers.size() ]) ;
 AlertDialog.Builder builder = new AlertDialog.Builder(SimonCallLogActivity.this);
 builder.setTitle("Choose a number:");
 builder.setItems(items, new DialogInterface.OnClickListener() {

public void onClick(DialogInterface dialog, int item) {
//TODO Auto-generated method stub
String selectedNumber = items[item].toString();
selectedNumber= selectedNumber.replace("-","");
selectedNumber= selectedNumber.replace("Home:","");
selectedNumber= selectedNumber.replace("Mobile:","");
selectedNumber= selectedNumber.replace("Work:","");
selectedNumber= selectedNumber.replace("Other:","");
//selectedNumber = selectedNumber.replace("+",""); 

 number.setText(selectedNumber); 
}
});
 AlertDialog alert = builder.create();
 if(logNumbers.size()>1){
 alert.show();

 }else{
 String selectedNumber= phoneNo.toString();
 selectedNumber=selectedNumber.replace("-","");

 number.setText(selectedNumber); 
 }
 if(phoneNo.length()==0){
 Log.d("SIMON","No contact"); 
 } 
 }
 break; 
 }
}else
{
//gracefully handle failure
Log.w("SIMON","Warning activity not okay");
}
}
}

时间: 原作者:

0 0

logNumbersnumber 声明为 SimonCallLogActivity 类的成员。


public class SimonCallLogActivity extends Activity {

/** Member variables */
 EditText display;
 Button log;

 List<String> logNumbers = new ArrayList<String>();
 EditText number;
. . .
. . .

}

移除它们的本地声明。

原作者:
...