由于存在getText()

时间:2019-02-16 00:43:30

标签: java android

这是我的问题,伙计们:

  1. 我在MainActivity上有一个对象列表(每个标题都必须单击标题和标题)
  2. 单击任一按钮,它们将被发送到SecondActivity。
  3. 除了getText()之外,其他所有方法都可以正常工作,这是我知道的唯一获取标题或 标题文字。
  4. 在编译时出现以下错误:“错误:找不到符号方法getText()”
  5. 我发誓我到处都在搜索答案并测试了所有答案。
  6. 请忍受我。我是Android新手。感谢您的帮助。

这是我编写的相关代码:

import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.RecyclerView;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.Toolbar;
import android.os.Bundle;
import android.app.AlertDialog;
import android.app.Dialog;
import android.content.DialogInterface;
import android.content.Intent;
import android.graphics.Color;
import android.util.Log;
import android.view.Gravity;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.Button;
import android.widget.LinearLayout;
import android.widget.TextView;
import android.widget.Toast;

public class MainActivity extends AppCompatActivity
{
public void onButtonClick(View v){
 Intent myIntent = new Intent(getBaseContext(),SecondActivity.class);
 startActivity(myIntent);
}

public void onTitleOrHeaderClick(View v)
{
    int    length;
    Intent intentToSecondActivity = new Intent(getBaseContext(),SecondActivity.class);
String tipHeader = v.getText();   /* for some reason getText() isn't recognized by the emulator */

intentToSecondActivity.putExtra("EXTRA_SESSION_ID","GOING to SecondActivity");

length = this.itemArray.tipObject.size();
for (int idx = 0; idx < length; idx++)
{
  if(this.itemArray.tipObject.get(idx).get(1) == v.getText())
    intentToSecondActivity.putExtra("EXTRA_SESSION_ID",v.getText());
}
}
}

1 个答案:

答案 0 :(得分:0)

将v广播到Textview(标题和标题的类类型):

public void onTitleOrHeaderClick(View v){
    int    length;
    TextView view=(TextView) v
    Intent intentToSecondActivity = new Intent(getBaseContext(),SecondActivity.class);
    String tipHeader = view.getText();   /* for some reason getText() is recognized now */
    intentToSecondActivity.putExtra("EXTRA_SESSION_ID","GOING to SecondActivity");
    length = this.itemArray.tipObject.size();
    for (int idx = 0; idx < length; idx++){
          if(this.itemArray.tipObject.get(idx).get(1) == view.getText())
              intentToSecondActivity.putExtra("EXTRA_SESSION_ID",view.getText());
        }
}