-1
我正在研究一个简单的应用程序来收集股票的当前信息。我正在应用AsyncTask,并且我已经构建了我的GUI,但是在我的EditText中输入股票代码后,似乎没有发生任何事情。任何援助非常感谢。我试着用Google搜索这些主题,看看文档和教程,但不知道我缺少什么。我约2个月学习Android开发。AndroidDev:股票应用程序的AsyncTask - 什么都没有发生
这里是我的代码:
package cornez.com.stockquotes;
import android.content.Context;
import android.graphics.Bitmap;
import android.os.AsyncTask;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.KeyEvent;
import android.view.WindowManager;
import android.view.inputmethod.EditorInfo;
import android.view.inputmethod.InputMethodManager;
import android.widget.EditText;
import android.widget.TextView;
import java.io.IOException;
public class MainActivity extends AppCompatActivity {
EditText editText;
String symbol;
TextView symbolText;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
TextView nameText, tradePriceText, tradeTimeText, changeText, rangeText;
symbolText = (TextView) findViewById(R.id.symbolText);
nameText = (TextView) findViewById(R.id.nameText);
tradePriceText = (TextView) findViewById(R.id.tradePriceText);
tradeTimeText = (TextView) findViewById(R.id.tradeTimeText);
changeText= (TextView) findViewById(R.id.changeText);
rangeText = (TextView) findViewById(R.id.rangeText);
editText = (EditText) findViewById(R.id.editText);
editText.setOnEditorActionListener(new TextView.OnEditorActionListener()
{
@Override
public boolean onEditorAction(TextView v, int actionId,
KeyEvent event)
{
if (actionId == EditorInfo.IME_ACTION_DONE)
{
// actions when "Done" key is pressed
InputMethodManager imm = (InputMethodManager)v.getContext().getSystemService(Context.INPUT_METHOD_SERVICE);
imm.hideSoftInputFromWindow(v.getWindowToken(), 0);
return true;
}
return false;
}
});
editText.requestFocus();
getWindow().setSoftInputMode(WindowManager.LayoutParams.
SOFT_INPUT_STATE_VISIBLE);
getStockInfoTask stockTask = new getStockInfoTask();
symbol = editText.getText().toString();
stockTask.execute(symbol);
}
//AsyncTask
private class getStockInfoTask extends AsyncTask<String, Void, Stock>
{
protected Stock doInBackground(String... params)
{
Stock stock = new Stock(symbol);
try {
stock.load();
} catch (IOException e) {
e.printStackTrace();
}
return stock;
}
protected void onPostExecute(Stock stock)
{
symbolText.setText(stock.getSymbol());
}
}
}
我试图在任何情况下,我的股票类添加代码,希望看到太多,但它不会让我。 – DJPharaohCHS