I'm inflating and running VideoViews in ViewPager2 via RecyclerView.Adapter. waiting for videos to load is so boring so i need a preloader how can i do that ?
This is my code:
String link = "https://media.istockphoto.com/videos/vertical-video-portrait-of-woman-standing-being-covered-in-coloured-video-id1255001964";
String link1 = "https://media.istockphoto.com/videos/aerial-vertical-video-valley-view-cave-and-fairy-chimneys-ancient-video-id1306879287";
String link2 = "https://media.istockphoto.com/videos/underground-and-overground-view-of-4k-vertical-timelapse-of-an-sour-video-id1203927026";
String link3 = "https://v77.tiktokcdn.com/562c58c18d346d0284b3604807e8f89d/60c74679/video/tos/alisg/tos-alisg-pve-0037c001/edb2701ce28b4ccc843809c5cea87b66/?a=1233&br=1608&bt=804&cd=0%7C0%7C1&ch=0&cr=0&cs=0&cv=1&dr=0&ds=3&er=&l=2021061406062101019020921612F5BAA4&lr=tiktok_m&mime_type=video_mp4&net=0&pl=0&qs=0&rc=M2ZrOztrNm5zNDMzOzczM0ApZTZkPGRkZGVoNzk5ZmQ5NGdgZ2ticjU1Y2RgLS0vMTRzczEtX2E2LmAuNGJhNDNiLmE6Yw%3D%3D&vl=&vr=";
String link4 = "https://v16m.tiktokcdn.com/6dd393d411e959580368c0229596fba5/60c7479f/video/tos/alisg/tos-alisg-pve-0037c001/b34ba40288a240f391fcc3e22af93a2e/?a=1233&br=2740&bt=1370&cd=0%7C0%7C1&ch=0&cr=0&cs=0&cv=1&dr=0&ds=3&er=&l=202106140611360101890720343CF4FEB9&lr=tiktok_m&mime_type=video_mp4&net=0&pl=0&qs=0&rc=MzlnZThseWU5NTMzODczM0ApZjg0N2hlNDw8N2Y2aTxkNGdnMGJpXjZsbnFgLS1kMTRzczEtNjZgNjViNjMyNTQ1NC86Yw%3D%3D&vl=&vr=";
ViewPager2 viewPager;
List<VideoData> list;
VideoAdapter adapter;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
viewPager = findViewById(R.id.viewPager);
//viewPager.setClipChildren(true);
//viewPager.setClipToPadding(true);
//viewPager.setOffscreenPageLimit(1);
//viewPager.setCurrentItem(1);
list = new ArrayList<>();
list.add(new VideoData(link));
list.add(new VideoData(link1));
list.add(new VideoData(link2));
list.add(new VideoData(link3));
list.add(new VideoData(link4));
adapter = new VideoAdapter(list);
adapter.notifyDataSetChanged();
viewPager.setAdapter(adapter);
Related
mainActivity has button. After button is clicked a popup message show having a button and a TextInputLayout.
data is sent to a tabbed acticity having 2 fragments and
the data is shown in textview of first fragment. Error is the data wont show in the textview while running
adapter for 2 fragments--
public class adapter extends FragmentPagerAdapter {
public adapter(#NonNull FragmentManager fm) {
super(fm);
}
#NonNull
#Override
public Fragment getItem(int position) {
Fragment fragment;
if (position == 1) {
fragment = new SecondFragment();
} else {
fragment = new FirstFragment();
}
return fragment;
}
#Override
public int getCount() {
return 2;
}
#Nullable
#Override
public CharSequence getPageTitle(int position) {
String title = null;
if (position == 0) {
title = "TextView";
} else if (position == 1) {
title = "Listview";
}
return title;
}
}
mainActivity(having popup window on clicking button)
myDialog = new Dialog(this);
}
//for for joining match
public void ShowPopup(View view) {
myDialog.setContentView(R.layout.popup);
myDialog.getWindow().setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT));
myDialog.show();
name = myDialog.findViewById(R.id.ig_name);
String igname = Objects.requireNonNull(name.getEditText()).getText().toString();
entry = myDialog.findViewById(R.id.entry);
entry.setOnClickListener(v -> {
Intent intent = new Intent(getApplicationContext(), secondActivity.class);
intent.putExtra("igname", igname);
startActivity(intent);
finish();
});
}
}
my firstFragment
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
// Inflate the layout for this fragment
View view = inflater.inflate(R.layout.fragment_first, container, false);
secondActivity activity = (secondActivity) getActivity();
TextView output = view.findViewById(R.id.textshow);
Bundle results = activity.getMyData();
String value1 = results.getString("value");
output.setText(value1);
return view;
}
secondActivity (intent is transfered from popup window)
public class secondActivity extends AppCompatActivity {
private String name;
TabLayout tabLayout;
ViewPager viewPager;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_second);
viewPager = findViewById(R.id.view_pager);
viewPager.setAdapter(new adapter(getSupportFragmentManager()));
tabLayout = findViewById(R.id.tabs_layout);
tabLayout.setupWithViewPager(viewPager);
Intent intent = getIntent();
name = intent.getExtras().getString("igname");
}
public Bundle getMyData() {
Bundle bundle = new Bundle();
bundle.putString("value", name);
return bundle;
}
}
Get the "igname" String value in onClickListner & also dismiss the dialog before finishing the activity.
entry.setOnClickListener(v -> {
String igname = Objects.requireNonNull(name.getEditText()).getText().toString();
Intent intent = new Intent(getApplicationContext(), secondActivity.class);
intent.putExtra("igname", igname);
startActivity(intent);
finish();
});
I am making a listView and in each item, there is a TextView identifying the field, and an EditText for the user to fill out the value. When I input the text into the EditText, the text just reverts back to what it was before. How do I make it so that it saves the new input? I read an article on StackOverflow of someone with a similar problem and they suggested using a TextOnChanged listener, so I added that as well. When I ran my app, the app just froze. I think I am doing it wrong so it would be great if someone helped me. Thanks.
Here is my code for my custom adapter:
public class DataListAdapter extends ArrayAdapter<DataObject> {
private Context mContext;
int mResource;
public DataListAdapter(Context context, int resource, List<DataObject> objects) {
super(context, resource, objects);
mResource = resource;
mContext = context;
}
#NonNull
#Override
public View getView(int position, #Nullable View convertView, #NonNull ViewGroup parent) {
String field = getItem(position).getField();
String value = getItem(position).getValue();
String unit = getItem(position).getUnit();
DataObject dataObject = new DataObject(field, value, unit);
LayoutInflater layoutInflater = LayoutInflater.from(mContext);
convertView = layoutInflater.inflate(mResource, parent, false);
TextView tvField = (TextView) convertView.findViewById(R.id.Field);
final EditText tvValue = (EditText) convertView.findViewById(R.id.Value);
tvField.setText(field);
tvValue.setText(value);
//the code I attempted to use to save the changed text
tvValue.addTextChangedListener(new TextWatcher() {
#Override
public void beforeTextChanged(CharSequence s, int start, int count, int after) {
}
#Override
public void onTextChanged(CharSequence s, int start, int before, int count) {
String edit = s.toString();
tvValue.setText(edit);
}
#Override
public void afterTextChanged(Editable s) {
}
});
return convertView;
}
}
Here is my code for the main activity for now if needed:
public class MainActivity extends AppCompatActivity {
ListView list;
ArrayList<DataObject> data = new ArrayList<>();
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
list =(ListView) findViewById(R.id.list);
data.add(new DataObject("Vitamin A", "14", ""));
data.add(new DataObject("Vitamin B", "15", ""));
data.add(new DataObject("Vitamin C", "16", ""));
DataListAdapter dataAdapter = new DataListAdapter(this, R.layout.row, data);
list.setAdapter(dataAdapter);
}
}
Hello everyone i have a problem with recyclerview
the app works in my emulator bluestacks but when I started testing on other devices the program gives such an error recyclerview No adapter attached; skipping layout
this fragment activity code:
public class AsosiyFragment extends Fragment {
#Override
public void onCreate(#Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
}
#Nullable
#Override
public View onCreateView(#NonNull LayoutInflater inflater, #Nullable ViewGroup container, #Nullable Bundle savedInstanceState) {
View rootView = inflater.inflate(R.layout.form_asosiy, container, false);
return rootView;
}
#Override
public void onViewCreated(#NonNull View view, #Nullable Bundle savedInstanceState) {
super.onViewCreated(view, savedInstanceState);
DBAdapter mDBAdapter = new DBAdapter(getContext());
Spinner spinner_viloyatlar = view.findViewById(R.id.spinner_viloyatlar);
RecyclerView recyclerView = view.findViewById(R.id.roza_vaqtlari);
recyclerView.setHasFixedSize(true);
Context context = view.getContext();
LinearLayoutManager layoutManager = new LinearLayoutManager(context);
layoutManager.setOrientation(LinearLayoutManager.VERTICAL);
recyclerView.setLayoutManager(layoutManager);
List<RamazonAdapter> ramazonAdapters = new ArrayList<>();
ramazonAdapters.clear();
String[] VILOYAT_NOMI_KIRIL = {
"Андижон","Бухоро",
"Жиззах","Қашқадарё",
"Қорақалпоғистон","Навоий",
"Наманган","Самарқанд",
"Сурхондарё","Сирдарё",
"Тошкент","Фарғона",
"Хоразм"
};
// Add viloyatlar to spinner
ArrayList<String> list = new ArrayList<String>();
for (int i = 0; i <= 12; i++){
list.add(VILOYAT_NOMI_KIRIL[i]);
}
ArrayAdapter<String> adapter = new ArrayAdapter<String>(getContext(),R.layout.spinner_item,R.id.item,list);
spinner_viloyatlar.setAdapter(adapter);
// get all data from sqlite
Cursor res = mDBAdapter.getAllData();
final RamazonAdapter[] rAdapters = {null};
while (res.moveToNext()){
String data1 = res.getString(1);
String data2 = res.getString(2);
String data3 = res.getString(3);
String data4 = res.getString(4);
rAdapters[0] = new RamazonAdapter(data1,data2,data3,data4);
ramazonAdapters.add(rAdapters[0]);
Adapter adapter1 = new Adapter(getActivity(), ramazonAdapters);
adapter.notifyDataSetChanged();
recyclerView.setAdapter(adapter1);
}
}
}
this adapter:
public class Adapter extends RecyclerView.Adapter<Adapter.ViewHolder>{
Context context;
private List<RamazonAdapter> ramazonAdapterList;
public Adapter(Context context, List<RamazonAdapter> ramazonAdapterList){
this.context = context;
this.ramazonAdapterList = ramazonAdapterList;
}
#NonNull
#Override
public Adapter.ViewHolder onCreateViewHolder(#NonNull ViewGroup parent, int viewType) {
View view = LayoutInflater.from(context).inflate(R.layout.ramazon_item,parent,false);
return new Adapter.ViewHolder(view);
}
#Override
public void onBindViewHolder(#NonNull Adapter.ViewHolder holder, int position) {
RamazonAdapter ramazonAdapter = ramazonAdapterList.get(position);
holder.nameOfDay.setText(ramazonAdapter.getNameOfDay());
holder.dateOfRoza.setText(ramazonAdapter.getDate());
holder.iftorlikTime.setText(ramazonAdapter.getIftorlikTime());
holder.saharlikTime.setText(ramazonAdapter.getSaharlikTime());
}
#Override
public int getItemCount() {
return ramazonAdapterList.size();
}
class ViewHolder extends RecyclerView.ViewHolder {
TextView nameOfDay;
TextView dateOfRoza;
TextView iftorlikTime;
TextView saharlikTime;
public ViewHolder(#NonNull View itemView) {
super(itemView);
nameOfDay = itemView.findViewById(R.id.nameOfDay);
dateOfRoza = itemView.findViewById(R.id.dateOfRoza);
iftorlikTime = itemView.findViewById(R.id.iftorlikTime);
saharlikTime = itemView.findViewById(R.id.saharlikTime);
}
}
}
I found several answers on this topic and tried them but I didn’t succeed help please
I think the error you are facing is due to the below line code
Adapter adapter1 = new Adapter(getActivity(), ramazonAdapters);
adapter.notifyDataSetChanged();
recyclerView.setAdapter(adapter1);
in the above block of code you are trying to notify an adapter before setting the adapter to recyclerview
I'm loading an Image into an ImageView using a link, and I'm trying to pass this link from one activity to display on another activity by an Intent. However, the Image just seems to come up blank.
Below I have listed the code associated with the two activities, as well as the adapter of the RecyclerView that the information is being passed from in the first activity
ActivityOne.java
private ArrayList<String> mImageUrls = new ArrayList<>();
...
mImageUrls.add("https://data.oireachtas.ie/ie/oireachtas/member/id/Se%C3%A1n-Haughey.S.1987-04-25/image/large");
...
#Override
public void onNoteClick(int position) {
Intent intent = new Intent(this, ActivityTwo.class);
intent.putExtra("EXTRA_KEY_NAME", mNames.get(position));
intent.putExtra("EXTRA_KEY_IMAGE", mImageUrls.get(position));
startActivity(intent);
}
ActivityTwo.java
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_members_map_detailed);
tvMemberName = findViewById(R.id.tvClareMemberNameDetailed);
tvMemberParty = findViewById(R.id.tvClareMemberPartyDetailed);
tvMemberConstituency = findViewById(R.id.tvClareMemberConstituencyDetailed);
tvMemberAddress = findViewById(R.id.tvClareMemberAddressDetailed);
tvMemberEmail = findViewById(R.id.tvClareMemberEmailDetailed);
tvMemberPhone = findViewById(R.id.tvClareMemberPhoneDetailed);
tvMemberContributions = findViewById(R.id.tvClareMemberContributionsDetailed);
imgMember = findViewById(R.id.imgClareMemberImageDetailed);
Intent intent = getIntent();
String mName = intent.getStringExtra("EXTRA_KEY_NAME");
String mParty = intent.getStringExtra("EXTRA_KEY_PARTY");
String mConstituency = intent.getStringExtra("EXTRA_KEY_CONSTITUENCY");
String mAddress = intent.getStringExtra("EXTRA_KEY_ADDRESS");
Uri myUri = Uri.parse(intent.getStringExtra("EXTRA_KEY_IMAGE"));
String mEmail = intent.getStringExtra("EXTRA_KEY_EMAIL");
String mPhone = intent.getStringExtra("EXTRA_KEY_PHONE");
String mContributions = intent.getStringExtra("EXTRA_KEY_CONTRIBUTIONS");
tvMemberName.setText(mName);
tvMemberParty.setText(mParty);
tvMemberConstituency.setText(mConstituency);
tvMemberAddress.setText(mAddress);
tvMemberEmail.setText(mEmail);
tvMemberPhone.setText(mPhone);
tvMemberContributions.setText(mContributions);
imgMember.setImageURI(myUri);
Adapter information associated with Image
#Override
public void onBindViewHolder(#NonNull ViewHolder holder, int position) {
Glide.with(mContext)
.asBitmap()
.load(mImageUrls.get(position))
.into(holder.image);
holder.name.setText(mNames.get(position));
holder.party.setText(mParties.get(position));
When I click first or second item from 1st array list I get first item from array list two, but I need if i click second item on array list 1 I get shown second item from list two
public class SecondActivity extends AppCompatActivity {
ListView listView;
ArrayList<String> 1stArrayList;
ArrayList<String> 2ndArrayList;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.second_activity);
listView = (ListView) findViewById(R.id.listView);
1stArrayList = new ArrayList<>();
1stArrayList .add("A");
1stArrayList .add("B");
1stArrayList .add("C");
2ndArrayList = new ArrayList<>();
2ndArrayList.add("1");
2ndArrayList.add("2");
2ndArrayList.add("3");
ArrayAdapter<String> adapter = new ArrayAdapter<>(this, R.layout.item, 1stArrayList);
listView.setAdapter(adapter);
listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
#Override
public void onItemClick(AdapterView<?> adapterView, View view, int position, long l) {
String 2ndArrayList= listView.getItemAtPosition(position).toString();
SharedPreferences settings = getSharedPreferences("PREFS", 0);
SharedPreferences.Editor editor = settings.edit();
editor.putString("2ndArrayList ", 2ndArrayList );
editor.apply();
Intent intent = new Intent(getApplicationContext(), ThirdActivity.class);
startActivity(intent);
}
});
}
}
A possible solution would be getting the value directly from the array using the position of the view clicked. Like the following:
listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
#Override
public void onItemClick(AdapterView<?> adapterView, View view, int position, long l) {
String secListItem = secArrayList.get(position);
SharedPreferences settings = getSharedPreferences("PREFS", 0);
SharedPreferences.Editor editor = settings.edit();
editor.putString("2ndArrayList", secListItem );
editor.apply();
Intent intent = new Intent(getApplicationContext(), ThirdActivity.class);
startActivity(intent);
}
});
But you have to be sure that both the arrays will have the same size or you may have an IndexOutOfBoundsException.
Another solution would be using some Map with the values from arraylist1 and arraylist2, implementing a custom adapter that extends BaseAdapter, populating the views with the values from the first array with getView() and using getItem() to return the values from the second list, but that's harder to do.
Also if you don't mean to persist the item and only transfer them between activities, you can use the Intent to do it. In this way:
Intent intent = new Intent(getApplicationContext(), ThirdActivity.class);
Intent.putExtra("2ndArrayList", secListItem);
startActivity(intent);
And recover in the third activity with something like:
String secArrayItem = "";
Bundle extras = getIntent().getExtras();
if (extras != null) secArrayItem = extras.getString("2ndArrayList");