TextView.getText()。toString()崩溃

时间:2015-12-24 17:27:54

标签: android textview android-arrayadapter

在我的应用程序中有列表视图,在获取列表后,当单击某个特定项目时它会崩溃。请帮助我是android的新手。导致错误的代码我用特殊字符“hash”标记它

import android.app.ListActivity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import android.widget.TextView;
import android.widget.Toast;

public class ListViewClass extends ListActivity {
TextView clickedView;

@Override
public void onCreate(Bundle savedInstanceState) {

    super.onCreate(savedInstanceState);

    // storing string resources into Array
    String[] adobe_products =     getResources().getStringArray(R.array.adobe_products);

    // Binding resources Array to ListAdapter
    this.setListAdapter(new ArrayAdapter<String>(this,   R.layout.list_item, R.id.label, adobe_products));


    ListView lv = getListView();
 // listening to single list item on click
    lv.setOnItemClickListener(new OnItemClickListener() {



      public void onItemClick(AdapterView<?> parent, View args1, int position, long id) {
          // selected item 
         ################################################ 
         String product = ((TextView) args1).getText().toString();
         ################################################ 


          // Launching new Activity on selecting single List Item
          Intent i = new Intent(getApplicationContext(), SingleListItem.class);
          // sending data to new activity
          i.putExtra("product", product);
          startActivity(i); 




      }
    });       
}
}

2 个答案:

答案 0 :(得分:2)

替换该行
awk -F'[ |=]' '
{
id[$2] += $4
value[$2] += $5
occur[$2]++
}
END{
printf "%-8s%8s%8s%8s\n", "Gene", "Targets", "Average Depth", "Average GC"
for (i in id)       
printf "%-8s%8d%8.1f%8.1f\n", i, occur[i],value[i]/occur[i],id[i]/occur[i]
}' input

答案 1 :(得分:0)

实际上你有数组元素,为什么你试图从textview获取价值。 您可以使用adobe_products [position]获取所选项目文本。

lv.setOnItemClickListener(new OnItemClickListener() {

      public void onItemClick(AdapterView<?> parent, View args1, int position, long id) {
          // selected item 
         ################################################ 
         String product = adobe_products[position] ;//Editted area
         ################################################ 

          // Launching new Activity on selecting single List Item
          Intent i = new Intent(getApplicationContext(), SingleListItem.class);
          // sending data to new activity
          i.putExtra("product", product);
          startActivity(i); 
      }
    });