package com.example.Calc;
import android.R.string;
import android.app.ListActivity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import android.widget.Toast;
public class modes extends ListActivity {
/** Called when the activity is first created. */
public void onCreate(Bundle icicle) {
super.onCreate(icicle);
// Create an array of Strings, that will be put to our ListActivity
String[] names = new String[] { "Simple Calculator", "Tip Calculator", "Mortgage Calculator", "BMI",
"GPA Calculator"};
// Create an ArrayAdapter, that will actually make the Strings above
// appear in the ListView
this.setListAdapter(new ArrayAdapter<String>(this,
android.R.layout.simple_list_item_1, names));
}
@Override
protected void onListItemClick(ListView l, View v, int position, long id) {
super.onListItemClick(l, v, position, id);
string content;
if( content ="Simple Calculator")
{
// When clicked, Open the Next Screen
Intent r=new Intent(modes.this ,simplecalculator.class );
}
}
}
获取错误if(content =“simple calculator”) 我想当我点击简单的计算器它应该把我带到其他屏幕..我已经定义了一切,但我忘了if条件事情......一切都已完成..它只是条件如果.. 请帮忙,谢谢你的时间。
答案 0 :(得分:0)
我认为您需要if (content.equals("Simple Calculator"))
,而不是if (content = "Simple Calculator")
答案 1 :(得分:0)
protected void onListItemClick(ListView l, View v, int position, long id) {
String content = ((ArrayAdapter<String>)l.getAdapter()).getItem(position);
if( content.equals("Simple Calculator"))
{
// When clicked, Open the Next Screen
Intent r=new Intent(this ,simplecalculator.class );
startActivity(r);
}
}
一些事情:
1)请使用CamelCase作为您的班级名称。
2)字符串以一个大写字母开头(因为应该所有Java类)。
就是这样。