当前位置: 代码迷 >> Android >> Android学习一
  详细解决方案

Android学习一

热度:72   发布时间:2016-05-01 15:32:40.0
Android学习1

开始学习关于android的开发。按照视频上的步骤写出的拨号程序结果硬是编译错误!后来才发现是android sdk升级的缘故!结果查阅 资料终于解决了此问题!

/*HelloAndroid.java*/

package com.google.android.hello;

import android.app.ListActivity;
import android.content.ContentUris;
import android.content.Intent;
import android.database.Cursor;
import android.os.Bundle;
import android.provider.Contacts.People;
import android.view.View;
import android.widget.ListAdapter;
import android.widget.ListView;
import android.widget.SimpleCursorAdapter;

public class HelloAndroid extends ListActivity {
??
???? private ListAdapter mAdapter;
????
????? /** Called when the activity is first created. */
??? @Override
??? public void onCreate(Bundle icicle) {
??????? super.onCreate(icicle);
??????? Cursor c = getContentResolver().query(People.CONTENT_URI, null, null, null, null);
??????? startManagingCursor(c);
??????
??????? String[] columns = new String[]{People.NAME}; // Comment
??????? int[] names = new int[]{R.id.row_entry};
??????
??????? mAdapter = new SimpleCursorAdapter(this, R.layout.main, c, columns, names);
??????
??????? this.setListAdapter(mAdapter);
??? }
??
??? @Override
??? protected void onListItemClick(ListView l, View v, int position, long id){
???? super.onListItemClick(l, v, position, id);
????
???? Intent i = new Intent(Intent.CALL_ACTION);
????
???? Cursor c = (Cursor) mAdapter.getItem(position);
???? long phoneID = c.getLong(c.getColumnIndex(People.PREFERRED_PHONE_ID));
????
???? i.setData(ContentUris.withAppendedId(
????????? android.provider.Contacts.Phones.CONTENT_URI, phoneID));
????
???? this.startActivity(i);
??? }
}?

/*main.xml*/

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
??? android:orientation="horizontal"
??? android:layout_width="fill_parent"
??? android:layout_height="wrap_content"
??? >
<TextView?
??? android:layout_width="wrap_content"
??? android:layout_height="wrap_content"
??? android:text="Name:"
??? />
<TextView? android:id="@+id/row_entry"
??? android:layout_width="wrap_content"
??? android:layout_height="wrap_content"
??? />???
</LinearLayout>

/*AndroidManifest.xml*/

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
??? package="com.google.android.hello">
??? <uses-permission android:name="android.permission.READ_CONTACTS"/>
??? <uses-permission android:name="android.permission.CALL_PHONE"/>
??? <application android:icon="@drawable/icon">
??????? <activity android:name=".HelloAndroid" android:label="@string/app_name">
??????????? <intent-filter>
??????????????? <action android:name="android.intent.action.MAIN" />
??????????????? <category android:name="android.intent.category.LAUNCHER" />
??????????? </intent-filter>
??????? </activity>
??? </application>
</manifest>

1 楼 vwangzhen 2009-01-21  
如何 在显示的文字中所有A大写且是红色
2 楼 jirabotuo 2009-02-13  
楼主推荐个视频。
  相关解决方案