我的项目有点问题。我不知道如何将String-Array中的某些项连接到我的hashmap。
public class MainActivity extends AppCompatActivity {
private ListView lista;
private String[] figury;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
lista = (ListView) findViewById(R.id.listView);
opcjeListy();
}
private void opcjeListy(){
Resources res = getResources();
figury = res.getStringArray(R.array.figury);
lista.setAdapter(new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, figury));
// Binding resources Array to ListAdapter
lista.setOnItemClickListener(new AdapterView.OnItemClickListener() {
public void onItemClick(AdapterView<?> parent, View v, int pos, long id) {
Intent intent = new Intent(MainActivity.this, kwadrat.class);
intent.putExtra("figury", figury);
startActivity(intent);
}
});
}
}
HashMap<String, String> hm = new HashMap<>();
hm.put("figury", "1");
tx.setText(String.valueOf(hm));
}
<resources>
<string name="app_name">Geometria</string>
<string-array name="figury">
<item>Kwadrat</item>
<item>Prostokąt</item>
</string-array>
</resources>
最后我将在MainActivity listview中创建,当我点击某个项目时,必须打开已识别的活动。 我点击X - &gt; X活动。 我点击Y - &gt; Y活动。