Hello i have problem with my sms aplication.
import java.util.ArrayList;
import java.util.List;
import android.app.Activity;
import android.database.Cursor;
import android.net.Uri;
import android.os.Bundle;
import android.telephony.SmsManager;
import android.view.View;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import android.widget.TextView;
public class Smsfive extends Activity {
/** Called when the activity is first created. */
public void onCreate(Bundle savedInstanceState, ListView messages) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
ListView list = (ListView) findViewById开发者_Go百科(R.id.list);
List<String> msgList = getSMS();
for(int i = 0; i<msgList.size(); i++) {
System.out.println(msgList.get(i));
}
ArrayAdapter<String> adapter = new ArrayAdapter<String>(this,R.layout.main, msgList);
list.setAdapter(adapter);
list.setOnItemClickListener(new OnItemClickListener()
{
@Override
public void onItemClick(AdapterView<?> arg0, View arg1, int arg2,
long arg3) {
SmsManager m = SmsManager.getDefault();
String destinationNumber=(String) ((TextView)view).getText();
m.sendTextMessage(destinationNumber, null, destinationNumber, null, null);
**there is Error ((TextView)view)**
}
});
}
public List<String> getSMS() {
List<String> list = new ArrayList<String>();
Uri uri = Uri.parse("content://sms/inbox");
Cursor c = null;
try{
c = getApplicationContext().getContentResolver().query(uri, null, null ,null,null);
}catch(Exception e){
e.printStackTrace();
}
try{
for (boolean hasData = c.moveToFirst(); hasData; hasData = c.moveToNext()) {
final String address = c.getString(c.getColumnIndex("address"));
final String body = c.getString(c.getColumnIndexOrThrow("body"));
list.add("Number: " + address + ". Message: " + body);
}
}catch(Exception e){
e.printStackTrace();
}
c.close();
return list;
}
}
XML :
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
android:id="@+id/widget30"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
xmlns:android="http://schemas.android.com/apk/res/android"
>
<ListView
android:id="@+id/list"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
</ListView>
</LinearLayout>
Error: Description Resource Path Location Type view cannot be resolved to a variable Smsfive.java /Sms5/src/sms/five line 43 Java Problem.
Can somebody help me please?
It looks like you didn't rename your parameters for the template method that Eclipse put in for you, try changing:
public void onItemClick(AdapterView<?> arg0, View arg1, int arg2, long arg3)
To:
public void onItemClick(AdapterView<?> adapter, View view, int position, long id)
精彩评论