我有以下代码:
ArrayAdapter<String> adapter;
User user;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_your_parties);
user = getUserData();
fillUserParty(user);
fillAdapter(user);
ListView partiesListView = (ListView) findViewById(R.id.parties_list_view);
Button goToCreatePartyButton = (Button) findViewById(R.id.go_to_create_party_button);
if(adapter != null){
partiesListView.setVisibility(View.VISIBLE);
partiesListView.setAdapter(adapter);
}else{
goToCreatePartyButton.setVisibility(View.VISIBLE);
goToCreatePartyButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
startActivity(new Intent(YourPartiesActivity.this, CreatePartyActivity.class));
}
});
}
}
@Override
protected void onResume() {
super.onResume();
adapter.notifyDataSetChanged();
}
private void fillAdapter(User user){
List<Party> parties = user.getParties();
if(parties != null) {
for (int i = 0; i < parties.size(); i++) {
Party party = parties.get(i);
adapter.add(party.getName());
}
}
}
private void fillUserParty(User user){
SharedPreferences preferences = getSharedPreferences("Parties", MODE_PRIVATE);
int numOfParties = CreatePartyActivity.checkNumberOfParties(preferences);
for(int i=0; i<numOfParties; i++){
String partyName = preferences.getString("Name" + i, "");
if(partyName != ""){
int id = preferences.getInt("Id" + i, 0);
Party party = new Party(id, partyName);
user.joinParty(party);
}
}
}
public User getUserData(){
SharedPreferences preferences = getSharedPreferences("User", 0);
int id = preferences.getInt("Id", 0);
String username = preferences.getString("Username", "");
String name = preferences.getString("Name", "");
return new User(id, username, name);
}
如果.csv文件中有重复的列,则该列将不会包含在 using (var dt= new DataTable())
{
var connString = string.Format("Provider=Microsoft.Jet.OLEDB.4.0; Data Source=\"{0}\\\"; Extended Properties=\"text;HDR={1};FMT={2}\"", dir, headers, format);
var query = "SELECT * FROM [" + file + "]";
using (var conn = new SqlConnection(ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString))
{
using (var adapter = new OleDbDataAdapter(query, connString))
{
adapter.Fill(dt);
由于某种原因,正在处理重复的列,就好像该列不存在一样。