嗨我noob到android,我尝试使用rgb颜色代码显示数据库中的颜色,我使用hashmap来映射数据和字段的数据会来,但我有分贝的rgb颜色代码它会来正确我的问题是,它只会从数据库显示最后的颜色值..如何让所有的价值和色彩修正到文本字段..如何获得在android中使用hashmap的整体价值?
public class AndroidJSONParsingActivity extends Activity {
static String items;
static String items1;
static String dates;
static String finalDate;
int a,r,g,b;
ListView lv2;
TextView text1;
String COLOR;
private static final String TAG_JSONDataResult = "JSONDataResult";
private static final String TAG_GRPNAME = "GRPNAME";
private static final String TAG_QNT = "QTY";
private static final String TAG_BUDGET = "BUDGET";
private static final String TAG_STOCK = "STOCK";
private static final String TAG_DIFF = "DIFF";
private static final String TAG_DIFF_P = "DIFF_P";
private static final String TAG_COLOR = "COLOR";
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
lv2=(ListView)findViewById(R.id.list);
Bundle b=this.getIntent().getExtras();
items=b.getString("item");
items1=b.getString("item1");
dates=b.getString("date");
SimpleDateFormat dateFormat = new SimpleDateFormat(
"yyyy-MM-dd");
Date myDate = null;
try {
myDate = dateFormat.parse(dates);
} catch (ParseException e) {
e.printStackTrace();
}
SimpleDateFormat timeFormat = new SimpleDateFormat("yyyy-MM-dd");
finalDate = timeFormat.format(myDate);
torun();
}
public void torun() {
String myUrl;
myUrl = String.format("http://10.0.2.2:51382/RestServiceImpl.svc/jsons/?Location=%s&GROUP=%s&asondate=%s",items.replaceAll(" ","%20"),items1.replaceAll(" ","%20"),finalDate);
final ArrayList> contactList = new ArrayList>();
// Creating JSON Parser instance
JSONParser jParser = new JSONParser();
// getting JSON string from URL
try {
JSONObject json1 = jParser.getJSONFromUrl(myUrl);
// Getting Array of Contacts
JSONArray list = json1.getJSONArray(TAG_JSONDataResult);
// looping through All Contacts
for(int i = 0; i < list.length(); i++){
JSONObject c = list.getJSONObject(i);
String GRPNAME = c.getString(TAG_GRPNAME);
String QTY = c.getString(TAG_QNT);
String BUDGET = c.getString(TAG_BUDGET);
String STOCK = c.getString(TAG_STOCK);
String DIFF = c.getString(TAG_DIFF);
String DIFF_P = c.getString(TAG_DIFF_P);
COLOR = c.getString(TAG_COLOR);
// creating new HashMap
HashMap map = new HashMap();
map.put(TAG_GRPNAME, GRPNAME);
map.put(TAG_QNT, QTY);
map.put(TAG_BUDGET, BUDGET);
map.put(TAG_STOCK, STOCK);
map.put(TAG_DIFF, DIFF);
map.put(TAG_DIFF_P, DIFF_P);
map.put(TAG_COLOR,COLOR);
dataList.add(map);
}
} catch (JSONException e) {
e.printStackTrace();
}
/**
* Updating parsed JSON data into ListView
* */
ListAdapter adapter = new SimpleAdapter(this, dataList,
R.layout.list_item,
new String[] { TAG_GRPNAME, TAG_QNT, TAG_BUDGET, TAG_STOCK, TAG_DIFF, TAG_DIFF_P, },
new int[] {
R.id.l2, R.id.l3, R.id.l4, R.id.l5, R.id.l6, R.id.l7}){
@Override
public View getView(int position, View convertView, ViewGroup parent) {
View v = convertView;
if (v == null) {
LayoutInflater vi = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);
v = vi.inflate(R.layout.list_item, null);
}
text1 = (TextView) v.findViewById(R.id.l7);
HashMap map=dataList.get(position);
map.get(TAG_COLOR);
String[] ARGB = COLOR.split(" ");
String V1=ARGB[0];
String V2=ARGB[1];
String V3=ARGB[2];
String V4=ARGB[3];
a=Integer.parseInt(V1);
r=Integer.parseInt(V2);
g=Integer.parseInt(V3);
b=Integer.parseInt(V4);
text1.setBackgroundColor(Color.rgb(r,g,b));
return super.getView(position, v, parent);
}
};
lv2.setAdapter(adapter);
// Launching new screen on Selecting Single ListItem
}
2013-07-22
ibu
+0
在粘贴代码时,删除所有注释的代码并仅粘贴所需的代码,以便阅读。 –
+0
@AshishAggarwal感谢和抱歉.. –