如何设置和获取的各项的ID在Android上的微调 [英] How to set and get the id for the items in the spinner in Android
问题描述
我有像我一个问题包含了在公司工作的所有开发人员名字的微调。结果
我已经使用了 ArrayAdapter
具有的所有的开发商的名称的数组,它是从数据库中获取。
问题是,当我更新的名称开发领域,我得到这是不够的更新数据作为其可以是多个开发人员与公司名称相同的开发商只有名称。结果
所以现在我需要开发者的ID来更新它..结果
如何存储与微调
的开发商 ID ,这样我可以做到这一点。
例如,我想去做是我们在 HTML
::标签做
<选择>结果
<选项ID =1> Developer1< /选项>结果
<选项ID =2> Developer2< /选项>结果
<选项ID =3> Developer2< /选项>结果
<选项ID =4> Developer2< /选项>结果
< /选择>
其中 ID 连接将是数据库的标识。结果
我想在android的模仿这一点。
这在code,我已经使用存储阵列中的名称:
字符串alldevelopers = NULL;
尝试
{
ArrayList的<&的NameValuePair GT; postP =新的ArrayList<&的NameValuePair GT;();
alldevelopers = CustomHttpClient.executeHttpPost(/ fetchdevelopers.php,postP);
串respcl = alldevelopers.toString();
alldevelopersParser开发=新alldevelopersParser();
OW = dev.parseByDOM(respcl);
}
赶上(例外五){
e.printStackTrace();
}开发商的字符串[] =新的String [ow.length] // dev为一类对象
对于(INT N = 0; N< ow.length; N ++)
{
开发商[η] = ow.developer [n]的[2];
}
这是将旋转阵列的微调。
最后的微调DEVL =(微调)findViewById(R.id.towner);
devl.setOnItemSelectedListener(managetasks.this);
ArrayAdapter<串GT; b =
新ArrayAdapter<串GT; getApplicationContext()
android.R.layout.simple_spinner_item,开发者);
b.setDropDownViewResource(android.R.layout.simple_dropdown_item_1line);
devl.setAdapter(二);
当您在微调执行setOnItemSelectedListener那么你有方法,如
公共无效onItemSelected(适配器视图<>适配器视图,视图来看,
INT位置,长的id){}
这里
您可以findout微调选定的开发者名称的位置,并使用这个位置从阵列获取数据。
I have a problem like I had a Spinner containing the Names of all developers working in the Company.
I have used the ArrayAdapter
with a Array having the names of all the developers which is fetched from the database.
The problem is that when I update the Name Of Developer field, I get Only the Name of the Developer which is not enough to update the data as their can be multiple developers with the same name in the Company.
So now I require the id of the developers to update it..
How to store that id of the developers with the Spinner
so that I can achieve this.
For example, I want to do like is as that we do in HTML
::
<select>
<option id="1">Developer1</option>
<option id="2">Developer2</option>
<option id="3">Developer2</option>
<option id="4">Developer2</option>
</select>
where the id attached would be the database id.
I want to imitate this in android.
This the code that I have used to store the names in the array::
String alldevelopers = null;
try
{
ArrayList<NameValuePair> postP = new ArrayList<NameValuePair>();
alldevelopers = CustomHttpClient.executeHttpPost("/fetchdevelopers.php", postP);
String respcl = alldevelopers.toString();
alldevelopersParser dev = new alldevelopersParser();
ow = dev.parseByDOM(respcl);
}
catch (Exception e) {
e.printStackTrace();
}
String developers[] = new String[ow.length]; //dev is a class object
for (int n = 0; n < ow.length; n++)
{
developers[n] = ow.developer[n][2];
}
This is the Spinner that would spin the array..
final Spinner devl = (Spinner) findViewById(R.id.towner);
devl.setOnItemSelectedListener(managetasks.this);
ArrayAdapter<String> b =
new ArrayAdapter<String>getApplicationContext(),
android.R.layout.simple_spinner_item,developers);
b.setDropDownViewResource(android.R.layout.simple_dropdown_item_1line);
devl.setAdapter(b);
When you perform setOnItemSelectedListener on the spinner then you have method such as
public void onItemSelected(AdapterView<?> adapterView, View view,
int position, long id) {}
here you can findout the position of selected developer name of spinner and use this position to fetch data from array.
这篇关于如何设置和获取的各项的ID在Android上的微调的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!