我是一个 Android 菜鸟,并尽我所能理解它。我正在尝试制作一个 apk 只是为了好玩,更好地理解事物,而且,即使在谷歌搜索了很多之后,我还没有解决一个问题。所以,问题是我有一个只允许数字的 EditText,并且通过在其中插入一个数字,它将进入一个字符串,并从那里引入 setProgress 作为“百分比”。至少,这就是我想要它做的;因为,在将该值放入字符串并尝试在 setProgress 中将其读取为百分比之后,eclipse 不会让我:
The method setProgress(int) in the type ProgressBar is not applicable for the arguments (String)
这是代码:*不要打扰其他任何事情,这只是为了测试......
package com.example.singur;
import android.app.Activity;
import android.os.Bundle;
import android.view.KeyEvent;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.inputmethod.EditorInfo;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ProgressBar;
import android.widget.RatingBar;
import android.widget.Switch;
import android.widget.TextView;
import android.widget.TextView.OnEditorActionListener;
import android.widget.ToggleButton;
public class MainActivity extends Activity implements OnClickListener
{
Button button;
ToggleButton toggle;
TextView rateText;
TextView textProgress;
Switch legit;
EditText edit;
RatingBar rating;
ProgressBar progress;
int count = 0;
// int value = 0;
@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
button = (Button) findViewById(R.id.button);
toggle = (ToggleButton) findViewById(R.id.toggle);
rateText = (TextView) findViewById(R.id.rateText);
textProgress = (TextView) findViewById(R.id.textProgress);
legit = (Switch) findViewById(R.id.legit);
edit = (EditText) findViewById(R.id.edit);
rating = (RatingBar) findViewById(R.id.rating);
progress = (ProgressBar) findViewById(R.id.progress);
legit.setEnabled(false);
edit.setEnabled(false);
button.setOnClickListener(this);
toggle.setOnClickListener(this);
edit.setOnClickListener(this);
//rating.setOnRatingBarChangeListener(this);
}
public void onClick(View v)
{
switch(v.getId())
{
case R.id.button:
textProgress.setText("button clicked" + count + progress.getProgress());
count++;
progress.setProgress(count);
break;
case R.id.rating:
break;
case R.id.toggle:
if(toggle.isChecked() == true)
{
edit.setEnabled(true);
edit.setText("" + count);
//count++;
//progress.setProgress(count);
textProgress.setText("button clicked" + count + progress.getProgress());
}else
{
edit.setEnabled(false);
edit.setText("disabled but count = " + count);
//count++;
//progress.setProgress(count);
textProgress.setText("button clicked" + count + progress.getProgress());
}
count++;
textProgress.setText("toggle:"+count);
break;
case R.id.edit:
if(edit.isEnabled() == true)
{
edit.setOnEditorActionListener(new OnEditorActionListener()
{
@Override
public boolean onEditorAction(TextView v, int actionId, KeyEvent event)
{
if (actionId == EditorInfo.IME_ACTION_DONE)
{
// do your stuff here
String value = edit.getText().toString();
progress.setProgress(value.valueOf(value));
}
return false;
}
});
}
}
}
}