从对象获取值

时间:2014-05-03 03:14:29

标签: java sqlite object hashmap onlongclicklistener

我尝试了一些关于堆栈溢出的解决方案,但它们似乎对我不起作用。

我使用以下onlongclicklistener

Object j = (Quote) MainActivity.this.adapter.getItem(position);

以下是我的对象J

现在我想将ticker的值变为字符串

我该如何解决这个问题。我需要Hashmap吗?

String valueofticker = j.toString(ticker); // How to do this ?

enter image description here

1 个答案:

答案 0 :(得分:1)

如果适配器中的项目是Quote对象列表,那么您可以这样做:

class Quote {
     private String ticker;

     // create getter and setter methods here for all
     // the variables in the Quote class.
}

使用此获取报价:

Quote qObj = (Quote) MainActivity.this.adapter.getItem(position);

获取这样的股票代码值:

String tickerValue = qObj.getTicker();
// the same will apply for all other variables of the class Quote.

希望有所帮助!

相关问题