Если вы хотите использовать диалог в контакте, вы должны создать свой собственный макет для контакта. См. Код ниже, например ...
при нажатии кнопки
public static final int NUMBER_SELECT = 1;
Intent intent = new Intent(clsBlockNumbers.this,CallLog_Activity.class);
startActivityForResult(intent,NUMBER_SELECT);
в том же упражнении записать / сделать onActivityResult
protected void onActivityResult(int requestCode, int resultCode, Intent data)
{
switch(requestCode) {
case NUMBER_SELECT:
if (resultCode == RESULT_OK) {
String number = data.getStringExtra("SelectedNumber");
if(number == null)
{
Toast.makeText(this, "No Record found: ", Toast.LENGTH_LONG).show();
}
else
{
//Your code
}
break;
}
}
}
CallLog_Activity.java
package com.demo;
import java.util.ArrayList;
import android.app.Activity;
import android.content.Intent;
import android.database.Cursor;
import android.net.Uri;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.view.Window;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.ListView;
import android.widget.TextView;
public class CallLog_Activity extends Activity implements OnItemClickListener
{
ArrayList<String> strAyyNumber,strAyyType,listNumber, strType, strAyyName ;
private CallLogListAdapter adapter ;
CallLog callLog;
String noType;
ListView listCallLog;
private String[] listCallLog_arr={};
Cursor cursor;
String strArr;
TextView tv, tv1, txtEmptyMsg;
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);
setContentView(R.layout.calllog_list);
callLog = new CallLog();
listCallLog = (ListView)findViewById(R.id.list);
strAyyNumber = new ArrayList<String>();
strAyyType = new ArrayList<String>();
strAyyName = new ArrayList<String>();
listNumber = new ArrayList<String>();
strType = new ArrayList<String>();
System.out.println("In Call log list activity");
try
{
final String[] projection = null;
final String selection = null;
final String[] selectionArgs = null;
final String sortOrder = "DATE DESC";
Cursor cursor = this.getContentResolver().query(
Uri.parse("content://call_log/calls"),
projection,
selection,
selectionArgs,
sortOrder);
if (cursor != null)
{
//Loop through the call log.
while (cursor.moveToNext())
{
//Common Call Log Items
String callNumber = cursor.getString(cursor.getColumnIndex(android.provider.CallLog.Calls.NUMBER));
strAyyNumber.add(callNumber);
String callType = cursor.getString(cursor.getColumnIndex(android.provider.CallLog.Calls.TYPE));
strAyyType.add(callType);
String callName = cursor.getString(cursor.getColumnIndex(android.provider.CallLog.Calls.CACHED_NAME));
strAyyName.add(callName);
}
for(int i=0;i<strAyyNumber.size();i++)
{
String no = strAyyNumber.get(i).toString();//.concat("\n").concat(strAyyType.get(i).toString());
Log.d("No length ", "No length ::" + no.length());
listNumber.add(no);
}
listCallLog_arr = listNumber.toArray(new String[listNumber.size()]);
Log.d("size", "list listCallLog_arr"+ listCallLog_arr.length);
if(!listNumber.isEmpty())
{
listCallLog.setVisibility(View.VISIBLE);
adapter = new CallLogListAdapter(CallLog_Activity.this,R.layout.calllog_list_row, listCallLog_arr,strAyyNumber,strAyyType,strAyyName);
listCallLog.setAdapter(adapter);
}
else
{
txtEmptyMsg = (TextView)findViewById(R.id.txtEmptyMsg);
txtEmptyMsg.setVisibility(View.VISIBLE);
txtEmptyMsg.setText("No Record found Press Back to Continue");
}
listCallLog.setOnItemClickListener(this);
}
listCallLog.setOnItemClickListener(this);
}
catch(Exception e)
{
e.printStackTrace();
}
}
@Override
public void onItemClick(AdapterView<?> arg0, View v, int position, long id)
{
String o = arg0.getItemAtPosition(position).toString();
Intent returnIntent = new Intent();
StringBuffer sb = new StringBuffer(o);
sb.reverse().setLength(10);
Log.d("Item click", "String buffer"+ sb);
String revercenum = sb.toString().trim();
Log.d("Item click", "revercenum "+ revercenum);
StringBuffer sb1 = new StringBuffer(revercenum);
sb1.reverse();
Log.d("Item click", "sb1 "+ sb1);
String revercenum1 = sb1.toString().trim();
revercenum1.replace("+", "");
Log.d("Item click", "revercenum 1"+ revercenum1);
returnIntent.putExtra("SelectedNumber",revercenum1.replace("+", ""));
setResult(RESULT_OK,returnIntent);
finish();
}
}
colllog_list.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<ListView
android:id="@+id/list"
android:layout_width="fill_parent" android:layout_height="fill_parent"
android:visibility="gone"
/>
<TextView android:id="@+id/txtEmptyMsg"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:gravity="center"
android:textStyle="bold"
android:textSize="25dp"
android:text=""
android:visibility="gone"
/>
</LinearLayout>
colllog_list_row.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="horizontal">
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical">
<TextView
android:id="@+id/txtCallLogName"
android:layout_width="wrap_content" android:layout_height="fill_parent"
android:textSize="20dp" android:layout_margin="10dp"
android:layout_weight="1" />
<TextView
android:id="@+id/txtCallLogNumber"
android:layout_width="wrap_content" android:layout_height="fill_parent"
android:textSize="20dp" android:layout_weight="1"
android:layout_marginLeft="10dp" android:layout_marginBottom="10dp"
android:layout_marginTop="5dp" android:layout_marginRight="10dp" />
</LinearLayout>
<TextView
android:id="@+id/txtCallLogType"
android:layout_width="wrap_content" android:layout_height="fill_parent"
android:textSize="12dp" android:layout_marginBottom="10dp"
android:layout_marginTop="10dp" android:layout_marginRight="10dp"
android:layout_alignParentRight="true" />
</RelativeLayout>
CallLogListAdapter.java
package com.Demo;
import java.util.ArrayList;
import android.app.Activity;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.TextView;
public class CallLogListAdapter extends ArrayAdapter<Object>
{
private static final String TAG = "CallLogListAdapter";
private LayoutInflater inflater = null;
private int resource;
private Activity activity;
CallLog callLog ;
String[] strTemp;
ArrayList<String> arrayItem = new ArrayList<String>();
ArrayList<String> ayyType = new ArrayList<String>();
ArrayList<String> tempType = new ArrayList<String>();
ArrayList<String> ayyName = new ArrayList<String>();
ArrayList<String> tempName = new ArrayList<String>();
ArrayList<String> tempName1 = new ArrayList<String>();
ArrayList<String> tempNo = new ArrayList<String>();
String strType, strName, strName1, strNo ;
String[] tmpName, tmpName1, tmpNo;
public CallLogListAdapter(Activity activity, int resorce, String[] strTemp, ArrayList<String> arryListNumber, ArrayList<String> arryListType, ArrayList<String> arryListName)
{
super(activity, resorce,strTemp);
this.resource = resorce;
this.activity = activity;
this.strTemp = strTemp;
Log.d("in adapter", "In Adapter");
arrayItem = arryListNumber;
ayyType = arryListType;
ayyName = arryListName;
}
@Override
public View getView(int position, View convertView, ViewGroup parent)
{
Log.d("in adapter", "In get View");
ViewHolder holder;
if (convertView == null)
{
LayoutInflater layoutInflater = LayoutInflater.from(getContext());
convertView = layoutInflater.inflate(resource, parent, false);
holder = new ViewHolder();
holder.txtName = (TextView)convertView.findViewById(R.id.txtCallLogName);
holder.txtNumber = (TextView)convertView.findViewById(R.id.txtCallLogNumber);
holder.txtType = (TextView)convertView.findViewById(R.id.txtCallLogType);
holder.txtName.setVisibility(View.VISIBLE);
try
{
for(int i=0;i<ayyName.size();i++)
{
strName = ayyName.get(i);
Log.d("in get view in ", "Name is: **"+ strName);
tempName.add(strName);
}
tmpName = tempName.toArray(new String[tempName.size()]);
if(tmpName[position] == null)
{
holder.txtName.setVisibility(View.GONE);
}
else
{
holder.txtName.setVisibility(View.VISIBLE);
holder.txtNumber.setTextSize(12);
holder.txtName.setText(""+ tmpName[position]);
}
}
catch (NullPointerException e)
{
e.printStackTrace();
}
for(int i=0;i<arrayItem.size();i++)
{
strNo = arrayItem.get(i);//.toString();
Log.d("in get view in ", "Number is: **"+ strNo);
tempNo.add(strNo);
}
String[] tmpNo = tempNo.toArray(new String[tempNo.size()]);
Log.d("in get view ", "Number is String[]** : "+ tmpNo[position]);
holder.txtNumber.setText(""+ tmpNo[position]);
for(int i=0;i<ayyType.size();i++)
{
strType = ayyType.get(i).toString();
if(strType.equalsIgnoreCase("1"))
{
strType = "Incoming Call";
}
else if(strType.equalsIgnoreCase("2"))
{
strType = "Outgoing Call";
}
else if(strType.equalsIgnoreCase("3"))
{
strType = "Missed Call";
}
tempType.add(strType);
}
String[] tmpType = tempType.toArray(new String[tempType.size()]);
holder.txtType.setText(""+ tmpType[position]);
convertView.setTag(holder);
} else {
holder=(ViewHolder)convertView.getTag();
}
return convertView;
}
public static class ViewHolder
{
private TextView txtNumber, txtType, txtName;
}
}
Я надеюсь, что это может помочь вам ..:)