Answer the question
In order to leave comments, you need to log in
How to display numbers from the call log in an array?
Help me please! How to display numbers from the call log in the phonesArray array. Only numbers. To then display the list.
import android.app.ListActivity;
import android.content.Intent;
import android.database.Cursor;
import android.net.Uri;
import android.os.Bundle;
import android.provider.CallLog;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.ListView;
import android.widget.Toast;
import java.util.ArrayList;
import java.util.Arrays;
public class MainActivity extends ListActivity implements AdapterView.OnItemLongClickListener {
final String[] phonesArray = new String[]{"0931111111", "0932222222", "0933333333",
"0934444444", "0935555555"};
private ArrayAdapter<String> mAdapter;
private ArrayList<String> phonesList = new ArrayList<>(Arrays.asList(phonesArray));
private View v;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
mAdapter = new ArrayAdapter<>(this,
android.R.layout.simple_list_item_1, phonesList);
setListAdapter(mAdapter);
getListView().setOnItemLongClickListener(this);
}
@Override
protected void onListItemClick(ListView l, View v, int position, long id) {
String apiUrl = "https://yandex.ua/search/?text=";
super.onListItemClick(l, v, position, id);
Intent browserIntent = new Intent(Intent.ACTION_VIEW,
Uri.parse(apiUrl + l.getItemAtPosition(position).toString()));
startActivity(browserIntent);
}
@Override
public boolean onItemLongClick(AdapterView<?> parent, View view, int position, long id) {
String selectedItem = parent.getItemAtPosition(position).toString();
Toast.makeText(getApplicationContext(),
selectedItem + " ok.",
Toast.LENGTH_SHORT).show();
return true;
}
}
Answer the question
In order to leave comments, you need to log in
Decided with receipt. How now by click to search for a number in Yandex?
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
if (ActivityCompat.checkSelfPermission(this, Manifest.permission.READ_CALL_LOG) != PackageManager.PERMISSION_GRANTED) {
// TODO: Consider calling
// ActivityCompat#requestPermissions
// here to request the missing permissions, and then overriding
// public void onRequestPermissionsResult(int requestCode, String[] permissions,
// int[] grantResults)
// to handle the case where the user grants the permission. See the documentation
// for ActivityCompat#requestPermissions for more details.
return;
}
Cursor cursor = getContentResolver().query(CallLog.Calls.CONTENT_URI,
null, null, null, CallLog.Calls.DEFAULT_SORT_ORDER);
startManagingCursor(cursor);
SimpleCursorAdapter adapter = new SimpleCursorAdapter(this,
android.R.layout.simple_list_item_1, cursor,
new String[] { CallLog.Calls.NUMBER},
new int[] { android.R.id.text1 });
setListAdapter(adapter);
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question