Skip to content

Commit

Permalink
Added onItemClick listener to open URL in a browser
Browse files Browse the repository at this point in the history
- Added a string that is show during the dialog box that appears during the time of choosing a browser when the user has clicked on an item in the profiles listView.
  • Loading branch information
akarsh committed Jan 14, 2019
1 parent c2244ac commit 3ddad88
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
package com.sakarsh.akarshseggemuresume;

import android.content.Intent;
import android.net.Uri;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ListView;

import com.google.gson.Gson;
Expand Down Expand Up @@ -35,11 +39,28 @@ protected void onCreate(Bundle savedInstanceState) {
String jsonString = bundle.getString("profiles");
Gson gson = new Gson();
Type listOfProfiles = new TypeToken<List<Profile>>() {}.getType();
List<Profile> profileArrayList = gson.fromJson(jsonString, listOfProfiles);
final List<Profile> profileArrayList = gson.fromJson(jsonString, listOfProfiles);
// Log.i("Profiles", "profiles array: "+profileArrayList);

ProfilesListAdapter profilesListAdapter = new ProfilesListAdapter(this, profileArrayList, imagesOfProfilesArrays);
listView = findViewById(R.id.listView);
listView.setAdapter(profilesListAdapter);

listView.setOnItemClickListener(new AdapterView.OnItemClickListener(){
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
// URL is being parsed and set to uri
Uri uri = Uri.parse(profileArrayList.get(position).getUrl());
// Intent is declared
Intent intent = new Intent(Intent.ACTION_VIEW);
// parsed URL is set to the intent
intent.setData(uri);
// Using string resource to show the text.
String title = (String) getResources().getText(R.string.chooser_title);
// Create and start chooser to show list of all browser apps installed on the device
Intent chooser = Intent.createChooser(intent, title);
startActivity(chooser);
}
});
}
}
1 change: 1 addition & 0 deletions akarshseggemuresume/app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,5 @@
<string name="place_of_birth">Place of birth</string>
<string name="english_resume" translatable="false">English resume</string>
<string name="deutsch_lebenslauf" translatable="false">Deutsch lebenslauf</string>
<string name="chooser_title">Complete action using</string>
</resources>

0 comments on commit 3ddad88

Please sign in to comment.