我需要这个应用来做一个简单的点击计数器这里是我的MainAvtivity的java脚本。 我设置了一个Button和TextView,但出于某种原因,当我在我的模拟器上运行它时,按下按钮时没有任何反应。如果有人有时间陪伴我,我愿意给你我的电子邮件地址。 请帮忙:(
这是MainActivity:
package com.example.myfirstapp;
import android.support.v7.app.ActionBarActivity;
import android.support.v4.app.Fragment;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.TextView;
public class MainActivity extends ActionBarActivity {
int TextView = 0;
TextView text;
public void count1(View v){
Button button = (Button) findViewById(R.id.button);
text = (TextView) findViewById(R.id.text);
button.setOnClickListener(new View.OnClickListener(){
@Override
public void onClick(View v){
// TODO Auto-generated method stub
TextView++;
text("count " + TextView);
}
});
}
protected void text(String string) {
// TODO Auto-generated method stub
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();
if (id == R.id.action_settings) {
return true;
}
return super.onOptionsItemSelected(item);
}
/**
* A placeholder fragment containing a simple view.
*/
public static class PlaceholderFragment extends Fragment {
public PlaceholderFragment() {
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View rootView = inflater.inflate(R.layout.fragment_main, container, false);
return rootView;
}
}
}
问题:我做错了什么? >:((((
答案 0 :(得分:0)
也许试试:
text.setText("Count " + TextView);