Skip to content

Commit 3ddad88

Browse files
committed
Added onItemClick listener to open URL in a browser
- 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.
1 parent c2244ac commit 3ddad88

File tree

2 files changed

+23
-1
lines changed

2 files changed

+23
-1
lines changed

akarshseggemuresume/app/src/main/java/com/sakarsh/akarshseggemuresume/ProfilesActivity.java

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,12 @@
11
package com.sakarsh.akarshseggemuresume;
22

3+
import android.content.Intent;
4+
import android.net.Uri;
35
import android.support.v7.app.AppCompatActivity;
46
import android.os.Bundle;
57
import android.util.Log;
8+
import android.view.View;
9+
import android.widget.AdapterView;
610
import android.widget.ListView;
711

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

4145
ProfilesListAdapter profilesListAdapter = new ProfilesListAdapter(this, profileArrayList, imagesOfProfilesArrays);
4246
listView = findViewById(R.id.listView);
4347
listView.setAdapter(profilesListAdapter);
48+
49+
listView.setOnItemClickListener(new AdapterView.OnItemClickListener(){
50+
@Override
51+
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
52+
// URL is being parsed and set to uri
53+
Uri uri = Uri.parse(profileArrayList.get(position).getUrl());
54+
// Intent is declared
55+
Intent intent = new Intent(Intent.ACTION_VIEW);
56+
// parsed URL is set to the intent
57+
intent.setData(uri);
58+
// Using string resource to show the text.
59+
String title = (String) getResources().getText(R.string.chooser_title);
60+
// Create and start chooser to show list of all browser apps installed on the device
61+
Intent chooser = Intent.createChooser(intent, title);
62+
startActivity(chooser);
63+
}
64+
});
4465
}
4566
}

akarshseggemuresume/app/src/main/res/values/strings.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,4 +20,5 @@
2020
<string name="place_of_birth">Place of birth</string>
2121
<string name="english_resume" translatable="false">English resume</string>
2222
<string name="deutsch_lebenslauf" translatable="false">Deutsch lebenslauf</string>
23+
<string name="chooser_title">Complete action using</string>
2324
</resources>

0 commit comments

Comments
 (0)